How can I accomplish this? Much thanks
Show date once (news script)
Moderator: General Moderators
Show date once (news script)
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
How can I accomplish this? Much thanks
- mydimension
- Moderator
- Posts: 531
- Joined: Tue Apr 23, 2002 6:00 pm
- Location: Lowell, MA USA
- Contact:
Simple code
date_ad is date field in MySQL
news is new for this date
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 />';
}
?>news is new for this date