Jump to content

can you group dates and months?


dbradbury

Recommended Posts

Of course it is.  Take the dates and explode them using the "/"  as the delimiter to get the individual parts.  Then display each piece of the exploded array to display as you see fit.

http://www.w3schools.com/PHP/func_string_explode.asp

right, so my code atm is:

<?php
include("connect.php");
$getbookings = mysql_query("SELECT * FROM phpbb_posts WHERE forum_id='10' ORDER BY post_subject DESC");
$topcid = $_GET['topic_id'];
$checkbookings = mysql_num_rows($getbookings);
?>
<table width="auto" height="auto" border="0" vspace="0" class="scrollable">
<?php
if($checkbookings==0)
{
echo 'No Bookings Yet';
}
else
{
while($row = mysql_fetch_assoc($getbookings))
{
$date = date('l jS F Y', strtotime($row['post_subject']));
echo '<tr><td width="auto" valign="top" align="right">'.$date.'</td><td width="20px" valign="top"><center> - </center></td><td width="auto">'.nl2br($row['post_text']).'</td></tr>';

}
}
?>
</table>

 

and now ill need to do

 

explode("/",$date)

 

then how would that do it?

 

im looking for something like this:

 

2010

      January

                  List of January items

      February

                List of February items

 

will it still work? if that is how i want it to be?

 

<style type="text/css">
.mnt {margin-left:30;}
.date {margin-left:60;
	float:left;
	display:inline;}
.text {}
</style>
<?php

include("connect.php");
$getbookings = mysql_query("SELECT * FROM phpbb_posts WHERE forum_id='10' ORDER BY post_subject DESC");
$topcid = $_GET['topic_id'];
$checkbookings = mysql_num_rows($getbookings);
if($checkbookings==0)
{
echo 'No Bookings Yet';
}
else
{
$year = '';
$mont = '';
while($row = mysql_fetch_assoc($getbookings))
{
	$y = substr($row['post_subject'], 0, 4);
	$m = substr($row['post_subject'], 5, 2);
	if ($y != $year){
		echo "<div class='year'>$y</div>\n";
		$year = $y;
		echo "<div class='mnt'>$m</div>\n";
		$mont = $m;
	}
	if ($m != $mont){
		echo "<div class='mnt'>$m</div>\n";
		$mont = $m;
	}
$date = date('l jS F Y', strtotime($row['post_subject']));
echo '<div class="date">'.$date.' - </div><div class="text">'.nl2br($row['post_text'])."</div>\n";

}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.