Jump to content

Reoccurring dates not showing


86Stang

Recommended Posts

Hello all,

I've recently been asked to figure out why the code for a webpage will suddenly no longer show events that have reoccurring dates.  Events that have been created withOUT reoccurring events are showing up just fine but any event flagged as reoccurring ain't showing its ugly mug.  Although I'm comfortable in PHP, I'm apparently not good enough to figure this out so I'm hoping that some nice PHP pro out there can help a fella out.


[code]
<?php

if (isset($event_id))
{
$qry = "SELECT * from events WHERE event_id = $event_id";
$result = mysql_query($qry) or die ("Error during Query!");
$row = mysql_fetch_array($result);

$lines = explode("\r\n", $row[info]);

$mq_link = "http://www.mapquest.com/maps/map.adp?city=" . urlencode($row[city]) . "&state=";
$mq_link .= "$row[state]&address=" . urlencode($row[street]) . "&zip=$row[zip]&country=us&zoom=6";

$mode_output .= "<p><font size=\"4\">$row[title]</font></p>";
$mode_output .= "<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\">";
$mode_output .= "<tr><td class=\"bodytext\">Date:</td><td class=\"bodytext\">" . date('F j, Y', strtotime($pdate)) . "</td></tr>";
$mode_output .= "<tr><td class=\"bodytext\">Time:</td><td class=\"bodytext\">$row[time]</td></tr>";
$mode_output .= "<tr><td class=\"bodytext\">Location:</td><td class=\"bodytext\"><a href=\"$mq_link\">$row[location]</a>";
$mode_output .= "&nbsp;&nbsp;<img src=\"images/mq_icon.gif\" border=\"0\"></td></tr>";

if ($row[fees] != "")
{
$mode_output .= "<tr><td class=\"bodytext\">Fees:</td><td class=\"bodytext\">$row[fees]</td></tr>";
}

if ($row[name] != "")
{
$mode_output .= "<tr><td class=\"bodytext\">Contact:</td><td class=\"bodytext\">$row[name]</td></tr>";
}

if ($row[email] != "")
{
$mode_output .= "<tr><td class=\"bodytext\">Email:</td><td class=\"bodytext\"><a href=\"mailto:$row[email]?subject=$row[title]\">$row[email]</a></td></tr>";
}

if ($row[phone] != "")
{
$mode_output .= "<tr><td class=\"bodytext\">Phone:</td><td class=\"bodytext\">" . substr_replace(substr_replace($row[phone], "-", 6, 0), "-", 3, 0) . "</td></tr>";
}

if ($row[website] != "")
{
$mode_output .= "<tr><td class=\"bodytext\">Website:</td><td class=\"bodytext\"><a href=\"http://$row[website]\">$row[website]</a></td></tr>";
}

$mode_output .= "</table>";

if ($row[image_url] != "")
{
$imagesize = getimagesize($row[image_url]);
$imagebox .= "<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" width=\"$imagesize[0]\" align=\"right\">\n";
$imagebox .= "<tr><td><img src=\"$row[image_url]\" width=\"$imagesize[0]\" height=\"$imagesize[1]\"></td></tr>\n";

if ($row[image_caption] != "")
{
$imagebox .= "<tr><td>$row[image_caption]</td></tr>\n";
}

$imagebox .= "</table>";
}

for ($i=0;$i<count($lines);$i++)
{
if ($i == 0)
{
$mode_output .= $imagebox;
}

$mode_output .= "<p class=\"bodytext\">" . stripslashes($lines[$i]) . "</p>";
}
}
else
{
$qry = "SELECT * FROM events ORDER BY start_date asc";
$result = mysql_query($qry) or die("Error during query!");

// get correct date formats
//$start_date = date("Ymd");
$start_date = date("20061231");
$end_date = date("Ymd", strtotime("20071231"));

while($row = mysql_fetch_array($result))
{
$i=0; // start counter

if ($row[recurs] == "Daily") // switchboard for recurring events
{
$recurs = 1;
}
if ($row[recurs] == "Weekly")
{
$recurs = 7;
}

// if the end date of the event is greater
// than the end date of the visit
// make the final end date the visit end date
if ($row[end_date] > $end_date)
{
$final_end_date = $end_date;
}
else
{
$final_end_date = $row[end_date];
}

if ($row[recurring] == "N")
{
if ($start_date <= $row[start_date] && $end_date >= $row[end_date])
{
$date[] = date('Ymd', strtotime($row[start_date] + $i));
$title[] = $row[title];
$time[] = $row[time];
$location[] = $row[location];
$street[] = $row[street];
$city[] = $row[city];
$state[] = $row[state];
$zip[] = $row[zip];
$id[] = $row[event_id];
}
}

if ($row[recurring] == "Y")
{
while (date('Ymd', strtotime($row[start_date] + $i)) <= $final_end_date)
{
if ($row[recurs] == "Monthly")
{
$recurs = date('t', strtotime($row[start_date] + $i)); // amnt of days in cur month
}

if ($row[start_date] + $i >= $start_date)
{
$date[] = date('Ymd', strtotime($row[start_date] + $i));
$title[] = $row[title];
$time[] = $row[time];
$location[] = $row[location];
$street[] = $row[street];
$city[] = $row[city];
$state[] = $row[state];
$zip[] = $row[zip];
$id[] = $row[event_id];
}
$i=$i+$recurs;
}
}
}

// make new array to sort and group later
for ($i=0;$i<count($date);$i++)
{
$prep[] = "$date[$i]|$time[$i]|$title[$i]|$location[$i]|$street[$i]|$city[$i]|$state[$i]|$zip[$i]|$id[$i]";
}

// ERROR CHECKING
if (isset($prep))
{
sort($prep); // sort array and group events
}
else
{
$mode_output = "<p class=\"txt\">Sorry, there are no events scheduled.";
}

if (!isset($mode_output)) // no problems have occured, ready to make itinerary
{
if (!isset($page))
{
$page = 1;
}

$qty = count($prep);
$limit = 30;
$maxpages = ceil($qty/$limit);
$offset = ($page - 1) * $limit;

/* WRITE NEXT-PREVIOUS LINKS TO TOP AND BOTTOM OF TABLE */
$nav = "";
if ($page > 1)
{
$pagenum = $page - 1;
$nav .= " <a href=\"?page=$pagenum\"><img src=\"images/btn_previous.gif\" border=\"0\"></a> &nbsp;&nbsp;";
}

if ($page < $maxpages)
{
$pagenum = $page + 1;
$nav .= " <a href=\"?page=$pagenum\"><img src=\"images/btn_next.gif\" border=\"0\"></a> ";
}

$mode_output .= "<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"0\">";
$mode_output .= "<tr><td class=\"bodytext\" colspan=\"2\">$nav</td></tr>";
$mode_output .= "<tr><td width=\"80\" class=\"sitewidehead\"><b>Date</b></td><td class=\"sitewidehead\"><b>Title</b></td></tr>";

for ($i=$offset;$i<($limit + $offset);$i++)
{
$contents = explode("|", $prep[$i]);
$pdate = $contents[0];
$fin_date = date('m-d-Y', strtotime($contents[0]));
$fin_title = $contents[2];
$fin_time = $contents[1];
$fin_location = $contents[3];
$fin_street = $contents[4];
$fin_city = $contents[5];
$fin_state = $contents[6];
$fin_zip = $contents[7];
$fin_id = $contents[8];
$mq_link = "http://www.mapquest.com/maps/map.adp?city=" . urlencode($fin_city) . "&state=";
$mq_link .= "$fin_state&address=" . urlencode($fin_street) . "&zip=$fin_zip&country=us&zoom=6";

if ($c % 2) // ALTERNATE ROW COLORS
{
$style = "tblbody1";
}
else
{
$style = "tblbody2";
}

$mode_output .= "<tr><td class=\"$style\">$fin_date</td>";
$mode_output .= "<td class=\"$style\"><a href=\"view_event.php?event_id=$fin_id&pdate=$pdate\">$fin_title</a></td></tr>";
$c++;

if (($i+1) >= $qty)
{
break;
}
}
$mode_output .= "<tr><td class=\"bodytext\" colspan=\"2\">$nav</td></tr>";
$mode_output .= "</table>";
}
}

?>


[/code]

Thanks in advance to anyone nice enough to help out!!

Link to comment
https://forums.phpfreaks.com/topic/33032-reoccurring-dates-not-showing/
Share on other sites

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.