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 . 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 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 pls give a solution...
hmm, i may be getting this wrongly, but do you actually want to fetch data with spaces in between groups? or just want to display them like that?
Just do a compare of the year part of the date and see if its different, if it is, echo a new line. If you could post your code here, I can suggest the changes that you need to do.
actually i want to display it on the website . code is as follows . $sql = $db->sql_query("SELECT * FROM ".REPORTS_TABLE." WHERE fin_publish='Yes' $WHERE ORDER BY fin_date DESC"); while ($res = $db->sql_fetchrow($sql)) { *********retrieving fields ***** )); PHP:
That SQL query is constructed wrong, I'm not sure how its working for you. Also, don't use "*" to retrieve all the fields in a table, always use the field names.
a stupid solution, keep check the years, if it is same as above, then echo a blank space.. $cdate=""; while ($res = $db->sql_fetchrow($sql)) { if ($cdate != $res["date"]) { echo "<br>"; } echo $res["title"] ." " .$res["date"] ."<br>"; $cdate=$res["date"]; }; Code (markup):