I have a PHP script which users submit a post and saves in to the database; I’m storing the date it was posted using time(). I’m trying to figure out a way to filter my data by day. I have a while loop which is returning all the posts that user made which is ordered by date, however what I’m looking to do is have headings of a date for e.g. 10 December 2011 and only have posts that was submitted on that day. I want it only to display the heading if there is data for that day.
Thanks a lot.
EDIT:
Here is my while loop at the moment:
$get_posts = mysql_query( "SELECT * FROM `posts` WHERE `userid` = '$name[id]' ORDER BY `date` DESC" );
while( $userpost = mysql_fetch_assoc( $get_posts ) )
{
echo $userpost[ 'post' ];
}
But somehow before the loop I need to display the date heading the post or posts was submitted. I’m thinking it would need to be a loop outside of the current loop but I have no idea how to go about it.
As you have mentioned in one of your comments to the question that the DB column is of type integer. And so I assume you are storing the UNIX timestamp in the column. From what I understand, you are looking to display something like:
And if that is correct, this code snippet might help:
Please note that I’ve used dummy column and table names, so please replace them with the actuals. Also, the above snippet will display heading in ascending order of date. To show in reverse, add DESC at the end of the query.
Hope the above helps!