dbradbury Posted February 17, 2010 Share Posted February 17, 2010 ive got a list of date in my forum, the post_subject is the date like 2010/01/29, but i have a large list, i was wondering if it possible to split these up, like say 2009, when its 2009 in the date, and then have a header for each month...? Quote Link to comment https://forums.phpfreaks.com/topic/192415-can-you-group-dates-and-months/ Share on other sites More sharing options...
premiso Posted February 17, 2010 Share Posted February 17, 2010 Yep, it is possible. Quote Link to comment https://forums.phpfreaks.com/topic/192415-can-you-group-dates-and-months/#findComment-1013853 Share on other sites More sharing options...
dbradbury Posted February 17, 2010 Author Share Posted February 17, 2010 good, but thats the thing, i dont have a clue where to start, i can get all dates to be shown, would it consist of while loops and if statements?? Quote Link to comment https://forums.phpfreaks.com/topic/192415-can-you-group-dates-and-months/#findComment-1013854 Share on other sites More sharing options...
gwolgamott Posted February 17, 2010 Share Posted February 17, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/192415-can-you-group-dates-and-months/#findComment-1013858 Share on other sites More sharing options...
dbradbury Posted February 17, 2010 Author Share Posted February 17, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/192415-can-you-group-dates-and-months/#findComment-1014051 Share on other sites More sharing options...
sasa Posted February 18, 2010 Share Posted February 18, 2010 <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"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/192415-can-you-group-dates-and-months/#findComment-1014182 Share on other sites More sharing options...
dbradbury Posted February 18, 2010 Author Share Posted February 18, 2010 that worked!! thanks sasa! only thing is now, that it is all left aligned.. :s but thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/192415-can-you-group-dates-and-months/#findComment-1014254 Share on other sites More sharing options...
dbradbury Posted February 18, 2010 Author Share Posted February 18, 2010 all done! Quote Link to comment https://forums.phpfreaks.com/topic/192415-can-you-group-dates-and-months/#findComment-1014260 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.