Page 1 of 1
Show date once (news script)
Posted: Thu Nov 28, 2002 6:27 pm
by Jim
Using a MySQL database to grab my news, I'd like to grab all news posts that were created on the same date and show them under a single date header.
How can I accomplish this? Much thanks

Posted: Thu Nov 28, 2002 9:27 pm
by mydimension
if you are using unix timestamps to store time than you can do a query to see if the dates fall within a certain range, namely 24hrs or 86400 seconds.
Posted: Fri Nov 29, 2002 3:59 am
by PaTTeR
You can use date/time function from MySQL - DATE_FORMAT() etc.
Posted: Fri Nov 29, 2002 4:13 am
by PaTTeR
Simple code
Code: Select all
<?php
.................
$query = "SELECT DATE_FORMAT(date_ad,'%Y%m%d') AS date, news
FROM news_table)";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result,MYSQL_ASSOC) {
$newsї$rowї'date']ї] = $rowї'news'];
}
while (list($date,$new) = each($news)) {
echo $date.'<br />';
while (list($key,$value) = each($new)) {
echo $value.'<br />';
}
echo '<br />';
}
?>
date_ad is date field in MySQL
news is new for this date