[PHP-DB] Select news based on dates
Hello, 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. TNX -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Select news based on dates
From: T. H. Grejc [EMAIL PROTECTED] 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... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Select news based on dates
Hi! You can use order by date and such method: code $result = mysql_query(blablabla); $date = foo; while($news = mysql_fetch_array($result)){ if ($date==$news[date]){ echo new date; } echo $news[text]; $date = $news[date]; } Monday, May 17, 2004, 3:50:04 PM, T. wrote: THG Hello, THG I would like to display my news like this: THG *10.04.2004.* THG - news 1 THG - news 2 THG - news 3 THG *14.04.2004.* THG - news 4 THG *15.04.2004.* THG - news 5 THG ... THG I'm thinking of some while loop but I'm not sure that it will work nor I THG know how to create that query. THG TNX -- Best regards, Mikhail U. Petrov mailto:[EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Select news based on dates
ORDER BY date, text ? Hi! You can use order by date and such method: code $result = mysql_query(blablabla); $date = foo; while($news = mysql_fetch_array($result)){ if ($date==$news[date]){ echo new date; } echo $news[text]; $date = $news[date]; } Monday, May 17, 2004, 3:50:04 PM, T. wrote: THG Hello, THG I would like to display my news like this: THG *10.04.2004.* THG - news 1 THG - news 2 THG - news 3 THG *14.04.2004.* THG - news 4 THG *15.04.2004.* THG - news 5 THG ... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php