...

View Full Version : Display date only for the first post



levani
02-19-2010, 11:54 AM
I'm creating standard php loop using the while function to display latest articles on my site and I want to display each date only once at the top of the article. Something like this:

19 February


Article title 1
Article title 2
Article title 3


18 February

Article title 4
Article title 5
Article title 6
Article title 7


17 February

Article title 8
Article title 9


and so on...

All the articles that is published on 18 February should be displayed under 18 February.

How can I do that using php? Can anyone please help?

Thanks in advance.

DaiWelsh
02-19-2010, 12:11 PM
Have a variable which holds the current "heading" (date) and each iteration of the loop check the current value against this and if different output new one and save. so (pseudocode)



$strHeading = '';
while(get data from database) {
if({date for this row} != $strHeading) {
$strHeading = {date for this row};
echo($strHeading)
}
}


HTH,

Dai



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum