arrange rows retrieved from database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rrn
Forum Commoner
Posts: 46
Joined: Wed Apr 15, 2009 7:54 am

arrange rows retrieved from database

Post 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...
Last edited by Benjamin on Sun May 03, 2009 6:13 am, edited 2 times in total.
Reason: Removed coloring, added code tags, removed abbreviation.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: arrange rows retrieved from database

Post by Benjamin »

Please post the code you have written and let us know where you are stuck. We will be happy to help.
rrn
Forum Commoner
Posts: 46
Joined: Wed Apr 15, 2009 7:54 am

Re: arrange rows retrieved from database

Post 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']))
    ));}
Last edited by Benjamin on Sun May 03, 2009 7:54 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: arrange rows retrieved from database

Post 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'];
}
 
 
Post Reply