Re: Select news based on dates

From: Date: Mon, 17 May 2004 13:13:54 +0000
Subject: Re: Select news based on dates
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-34455@lists.php.net to get a copy of this message
From: "T. H. Grejc" <php@1203.qwe.uni.cc> > I would like to display my news like this: > > *10.04.2004.* > - news 1 > - news 2 > - news 3 > *14.04.2004.* > - news 4 > *15.04.2004.* > - news 5 > ... > > I'm thinking of some while loop but I'm not sure that it will work nor I > know how to create that query. SELECT your data with the date and only display the date if it changes. $query = "SELECT * FROM table ORDER BY datecolumn ASC"; $result = mysql_query($query) or die(mysql_error()); $prevdate = ''; while($row = mysql_fetch_assoc($result)) { if($row['datecolumn'] != $prevdate) { echo '*' . $row['datecolumn'] . '*<br />'; $prevdate = $row['datecolumn']; } echo '- ' . $row['news'] . '<br />'; } ---John Holmes...

« previous php.db (#34455) next »