teynon Posted March 7, 2013 Share Posted March 7, 2013 What is your end goal of this "pagination" of months? Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 7, 2013 Author Share Posted March 7, 2013 Too look like the earlier post said Page 1 March 2013(heading from code I provided) 3/15/2013 - 7/18/2013 Test1 April 2013 3/15/2013 - 7/18/2013 Test1 May 2013 3/15/2013 - 7/18/2013 Test1 Page 2 June 2013 3/15/2013 - 7/18/2013 Test1 July 2013 3/15/2013 - 7/18/2013 Test1 August Left blank my table structure has start and end date and event name and id. Otherwise I'm not sure what you mean by my end goal Quote Link to comment Share on other sites More sharing options...
teynon Posted March 7, 2013 Share Posted March 7, 2013 What are you trying to make? Is it a datepicker of some sort? Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 7, 2013 Author Share Posted March 7, 2013 It is a registration system for users to register for events or classes or a limited time product. I would like events listed by the month that they are set to run through...thus the need to find the months that they are running through(this would be more of like an event that may run through mid month to beginning of a month...but could go for a while) Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 7, 2013 Author Share Posted March 7, 2013 Biggest reason why it may run through multiple months would be the sub events are different days running throughout the months Quote Link to comment Share on other sites More sharing options...
teynon Posted March 7, 2013 Share Posted March 7, 2013 (edited) Alright, well my first piece of advice would be to design it in Photoshop or on a piece of paper if you don't have Photoshop. As far as building the pagination goes, I don't know what more advice you need. The answer Barand posted gives you the information necessary for traversing through the months. Edited March 7, 2013 by teynon Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 7, 2013 Author Share Posted March 7, 2013 Well I have the code for the pagination and everything, it is combining the codes that is messing me up. I would have to use a couple of loops, the select from db loop, the pagination loop, then the month finder loop. Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 7, 2013 Author Share Posted March 7, 2013 But I'll try in the morning some more, maybe a good nights sleep will help me get it straight Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 7, 2013 Share Posted March 7, 2013 Especially the last one. Turn on error reporting. Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 7, 2013 Author Share Posted March 7, 2013 I think I may be somewhat close, but as I suspected, the loops are confusing me. here is what i have come up with : $offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0; $currMonth = date('n'); $list = array(); $list[] = mktime(0, 0, 0, $currMonth+$offset, 1); $list[] = mktime(0, 0, 0, $currMonth+$offset+1, 1); $list[] = mktime(0, 0, 0, $currMonth+$offset+2, 1); foreach ($list as $dateTS) { $sql = mysql_query("SELECT * FROM events"); while($row = mysql_fetch_array($sql)){ $start = $row["startdate"]; $end = $row['enddate']; date_default_timezone_set('America/Los_Angeles'); $start = new DateTime($start); $end = new DateTime($end); $inc = DateInterval::createFromDateString('first day of next month'); $end->modify('+1 day'); $p = new DatePeriod($start,$inc,$end); foreach ($p as $d) echo $d->format('M') . '<br>'; } echo date('M Y', $dateTS) . '<br />'; foreach ($p as $d) echo $d->format('M') . '<br>'; } $prev = $offset-3; $next = $offset+3; echo "<br><a href='?offset={$prev}'>Prev</a> <a href='?offset={$next}'>Next</a>"; currently, this just shows the list of three months with pagination. I am not sure where each loop should be placed Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 11, 2013 Author Share Posted March 11, 2013 so I finally have this working! <?php date_default_timezone_set('America/Los_Angeles'); error_reporting(E_ALL); ini_set("display_errors", 1); $offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0; $currMonth = date('n'); $list = array(); $list[] = mktime(0, 0, 0, $currMonth+$offset, 1); $list[] = mktime(0, 0, 0, $currMonth+$offset+1, 1); $list[] = mktime(0, 0, 0, $currMonth+$offset+2, 1);?> <table> <?php foreach ($list as $dateTS){ echo '<tr style="background-color:#CCC"><td>'; echo '<strong>'.date('F Y', $dateTS) . '</strong><br /> </td></tr>'; $sql = mysql_query("SELECT * FROM events where public='yes' order by id ASC"); while($row = mysql_fetch_array($sql)){ $start1 = $row["start"]; $end1 = $row['end']; $event = $row['name']; $id = $row['id']; $start = new DateTime($start1); $end = new DateTime($end1); $inc = DateInterval::createFromDateString('first day of next month'); $end->modify('+1 day'); $p = new DatePeriod($start,$inc,$end); foreach ($p as $d) if($d->format('M Y')==date('M Y', $dateTS)){ $originalDate = $start1; $newDate = date("m/d/Y", strtotime($originalDate));$originalDate1 = $end1; $newDate1 = date("m/d/Y", strtotime($originalDate1)); echo '<tr><td><a href="event.php?id='.$id.'">' .$newDate.' - '.$newDate1.' '.$event.'</a><br /></tr></td>'; } } } $prev = $offset-3; $next = $offset+3; echo "<br><a href='?offset={$prev}'>Prev</a> <a href='?offset={$next}'>Next</a>"; ?> I do have one issue though, how and where do I place a message that will display no events scheduled if the month has no events scheduled? Quote Link to comment Share on other sites More sharing options...
salathe Posted March 11, 2013 Share Posted March 11, 2013 I really need to learn to use the new DateInterval stuff. Very cool.The use of "new" there made me chortle. Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 11, 2013 Share Posted March 11, 2013 The use of "new" there made me chortle. Scuze me, "new-to-me" Quote Link to comment Share on other sites More sharing options...
salathe Posted March 11, 2013 Share Posted March 11, 2013 Scuze me, "new-to-me" You're 'scuzed. P.S. The DateInterval and DatePeriod classes are super-duper useful, everyone should use them! Quote Link to comment Share on other sites More sharing options...
Barand Posted March 11, 2013 Share Posted March 11, 2013 P.S. The DateInterval and DatePeriod classes are super-duper useful, everyone should use them! I'm certainly a convert. Quote Link to comment 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.