Page 1 of 1

arrange rows retrieved from database

Posted: Sun May 03, 2009 6:04 am
by rrn
in my website ( php , sql ) . i am retrieving certain rows from database table in the descending order of the date .

for eg : my table will look like this .

Code: Select all

 
title     date
 
aaaa  16/3/2009
bbbb  15/3/2009
cccc   6/2/2009
dddd   2/12/2008
eeee   1/12/2007
 
what i want to do is

i want to leave a space after each group of years.
ie the table should become as follows

Code: Select all

 
title     date
 
aaaa  16/3/2009
bbbb  15/3/2009
cccc   6/2/2009
 
dddd   2/12/2008
 
eeee   1/12/2007
 
how can i do that? somebody <d>pls</d> please give a solution...

Re: arrange rows retrieved from database

Posted: Sun May 03, 2009 6:12 am
by Benjamin
Please post the code you have written and let us know where you are stuck. We will be happy to help.

Re: arrange rows retrieved from database

Posted: Sun May 03, 2009 7:23 am
by rrn

Code: Select all

$sql = $db->sql_query("SELECT * FROM ".REPORTS_TABLE." WHERE fin_publish='Yes' $WHERE ORDER BY fin_date DESC");
while ($res = $db->sql_fetchrow($sql)) {
        
        'TITLE'     =>  $res['fin_title'.$theme[lang]],
             'DATE'     =>  date('d M, Y', strtotime($res['fin_date']))
    ));}

Re: arrange rows retrieved from database

Posted: Sun May 03, 2009 7:59 am
by Benjamin

Code: Select all

 
$sql = $db->sql_query("SELECT * FROM ".REPORTS_TABLE." WHERE fin_publish='Yes' $WHERE ORDER BY fin_date DESC");
while ($res = $db->sql_fetchrow($sql)) {
        
        'TITLE'     =>  $res['fin_title'.$theme[lang]],
             'DATE'     =>  date('d M, Y', strtotime($res['fin_date']))
             'YEAR'     =>  date('Y', strtotime($res['fin_date']))
    ));}
 
When displaying them:

Code: Select all

 
foreach ($foo as $record) {
    // rendering code start
 
    if (isset($year) && $year != $foo['YEAR']) {
        echo "<br />";
    }
 
    // rendering code stop
 
    // save the previous year before displaying the next record
    $year = $foo['YEAR'];
}