Jump to content

Recommended Posts

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

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)

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 by teynon

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 :(

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?  

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.