Thanks for the reply, it gave me an idea of how to do it with using MySQL timestamps. I have got it to work, sort ot 😉
However at the moment, I have 2 records both posted on the same day but different times. So the way I have grouped by date it will echo a group of 2 records twice, resulting in 4 records, 2 duplicates.
If I didnt explain that very well, heres an example:
2nd April 2004
An article
Another article
2nd April 2004
An article
Another article
And here is the code I used to do this.
$dates = new dbconnect();
$dates->query("SELECT DISTINCT date, DATE_FORMAT(date, '%M <B>%D</B> %Y') AS datestamp FROM blog ORDER BY date DESC");
while($date = $dates->fetch_object()) {
$content .= "<H1>$date->datestamp</H1>\n";
$blog = new dbconnect();
$blog->query("SELECT
blog.bid,
blog.cid,
blog.title,
blog.blog,
DATE_FORMAT(blog.timestamp, '%W %D %M, %H:%i%p') as timestamp,
users.username,
users.email
FROM blog, users
WHERE blog.uid = users.uid
AND blog.timestamp LIKE '$date->date%'
ORDER BY blog.timestamp DESC");
while ($row = $blog->fetch_object()) {
$comments = new dbconnect();
$comments->query("SELECT bcid FROM blog_comments WHERE bid = '$row->bid'");
$content .= "<H2>$row->title</H2>\n";
$content .= "$row->blog <BR />- <I><A href=\"mailto:$row->email\" title=\"Email $row->username\">$row->username</A></I>\n";
$content .= "<DIV id=\"footer\">Added $row->timestamp<br>\n";
$content .= "<A href=\"#\">(".$comments->num_rows().") comments so far</A> - <A href=\"#\">Add a comment </A></DIV>\n";
}
}
I know its something to do with the $dates query, but I am quite new and have no idea how to make MySQL only get 1 record for each 'date' field which is the same. (date field is timestamp(8), so in format YYYYMMDD)
Thanks for any help, and thanks again for getting me started tekky.