Jump to content

grouping posts by date


newb

Recommended Posts

i have a problem..my posts are showing up like this:

 

July 6:

post message

 

July 6:

post message

 

July 6:

post message

 

im trying to get it like this:

 

July 6:

post message

post message

post message

 

how do i group them like this in all in one post?

Link to comment
Share on other sites

$query = mysql_query("SELECT * FROM av_items  ORDER BY av_items.date DESC LIMIT 20");

	while ($row = mysql_fetch_assoc($query)) {
		$id = $row['id'];
		$date = $row['date'];
$message = $row['message'];

		$entry_date = date("Ymd", $date);
		if ($entry_date !== $called_date) {



		echo '<h1 class="topic">'.av_date($date) .'</h1>';
echo $message;
$called_date=$entry_date;
}
}

Link to comment
Share on other sites

 

Have you tried this? :

 

$query = mysql_query("SELECT * FROM av_items  GROUP BY month(date) ORDER BY av_items.date DESC LIMIT 20");

	while ($row = mysql_fetch_assoc($query)) {
		$id = $row['id'];
		$date = $row['date'];
$message = $row['message'];

		$entry_date = date("Ymd", $date);
		if ($entry_date !== $called_date) {



		echo '<h1 class="topic">'.av_date($date) .'</h1>';
echo $message;
$called_date=$entry_date;
}
}

Link to comment
Share on other sites

try

$query = mysql_query("SELECT * FROM av_items  ORDER BY av_items.date DESC LIMIT 20"); //remove GROUP BY part

	while ($row = mysql_fetch_assoc($query)) {
		$id = $row['id'];
		$date = $row['date'];
                                          $message = $row['message'];

		$entry_date = date("Ymd", $date);
		if ($entry_date !== $called_date) {



		echo '<h1 class="topic">'.av_date($date) .'</h1>';
//echo $message;
$called_date=$entry_date;
}echo $message, "<br />\n";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.