neogemima Posted May 11, 2009 Share Posted May 11, 2009 Hello, I have a php file that displays rows of a database by different criteria. One of the criteria displayed is the date in YYYY-MM-DD format, no big deal. Current output: 2008-06-15 Line of text 2008-06-15 Line of text 2008-06-14 Line of text Not very elegant with a long list. How can I, through php, display a header for a date, say 2008-06-15 on it's own line and then display just the rows beneath it's content text. I know how to display lines without the date in front, I just need to know a way of testing for a change in the date (which is just a field in the table) and then create a header line for that date. What I'm going for: 2008-06-15 //perhaps some i will add a background color and change font size Line of text Line of text 2008-06-14 Any suggestions appreciated. Thanks. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 11, 2009 Share Posted May 11, 2009 Initialize a variable to remember the last value before your loop. Then test if the remembered last value is not equal to the current value. If they are different, output the header like you want and set the remembered last value to be the current value. pseudo code - $last_value = ""; // initialize variable while($row = ....){ if($last_value != $row['date']){ // put code here to output the header $last_value = $row['date']; } // remainder of code } Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 11, 2009 Share Posted May 11, 2009 I would use ORDER BY date in your SQL if you're attempting PFMaBiSMAd's method. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.