Hello.
I’ve been looking at an event calendar that I found one suits my needs.
I made changes to the code to suit my needs, and now however, I want to make a couple more changes and would appreciate some help, as i’m stuck!.
The current calendar I have finds the date in the database for each event where the start_date happens and makes it a hyperlink in the calendar created.
Now what I want it to do is this:
Make the calendar find the start_date and end_date in my database for each event and makes the dates hyperlinks where they are EQUAL TO start_date OR BETWEEN OR EQUAL TO end_date.
Now I think I have my SQL statement right, but would anybody be able to help me understand how I can make the dates hyperlinks on the calendar for:
- The date the event starts (done already)
- The days in-between the events
- The end_date
So for example if an event started on 12th may and finished on 15th may the days. 12th, 13th, 14th and 15th would be hyperlinks in the calendar?
Thanks
Chris
<?php
// Old Query Was to Just get the date
//$sql = "SELECT start_date FROM cms_events GROUP BY start_date ORDER BY start_date";
// New Query Want to get the between dates?
$sql = "SELECT * FROM cms_events WHERE start_date >= CURRENT_DATE() AND end_date <= CURRENT_DATE()";
$qry = mysql_query($sql) or die("SQL Error: $sql<br" . mysql_error());
$arrEVENTS = array();
WHILE ($r = mysql_fetch_array($qry)) :
$arrEVENTS[$r['start_date']] = 1;
ENDWHILE;
$pMON = (isset($_GET['m']) ? $_GET['m'] : gmdate("Ym"));
$thisMONyy = substr($pMON,0,4);
$thisMONmm = substr($pMON,4,2);
$BOM = gmmktime(0,0,0,$thisMONmm,1,$thisMONyy);
$EOM = gmmktime(0,0,0,$thisMONmm+1,0,$thisMONyy);
$BOC = gmmktime(0,0,0,$thisMONmm,1-gmdate("w", $BOM),$thisMONyy);
$EOC = gmmktime(0,0,0,$thisMONmm+1,0+(6-gmdate("w",$EOM)),$thisMONyy);
$PREVmon = gmdate("Ym",gmmktime(0,0,0,$thisMONmm-1,1,$thisMONyy));
$NEXTmon = gmdate("Ym",gmmktime(0,0,0,$thisMONmm+1,1,$thisMONyy));
$PREVyear = gmdate("Ym",gmmktime(0,0,0,$thisMONmm,1,$thisMONyy-1));
$NEXTyear = gmdate("Ym",gmmktime(0,0,0,$thisMONmm,1,$thisMONyy+1));
print "<table style='smCal' cellspacing=0 cellpadding=0 bgcolor=c0c0c0>";
print "<tr bgcolor=navy>";
print "<td class='month' width='100%' colspan='7'>";
print "<table width='100%'><tr>";
print "<td align='left'>";
print "<a href='{$_SERVER['PHP_SELF']}?m=$PREVyear'>«</a> ";
print "<a href='{$_SERVER['PHP_SELF']}?m=$PREVmon'><</a>";
print "</td>";
print "<td class='month'>" . gmdate("F Y", $BOM) . "</td>";
print "<td align='right'>";
print "<a href='{$_SERVER['PHP_SELF']}?m=$NEXTmon'>></a>";
print "<a href='{$_SERVER['PHP_SELF']}?m=$NEXTyear'>»</a>";
print "</td>";
print "</tr></table>";
print "</td>";
print "<tr>";
print "<tr class='header'>";
$DOWheader = array("Su","Mo","Tu","We","Th","Fr","Sa");
foreach($DOWheader as $dow => $thisHEADER) :
print "<td align='right'><b>$thisHEADER</b></td>";
endforeach;
print "</tr>\
";
$rows = 0;
$x = $BOC;
DO {
$dow = gmdate("w", $x);
if ($dow == 0) : print "<tr>\
"; endif;
$thisSTYLE = "";
IF (isset($arrEVENTS[gmdate("Y-m-d",$x)])) :
$thisSTYLE = "style='color:DarkGreen;'";
ENDIF;
print "<td class='" . (gmdate("Ym",$x) == $pMON ? "active" : "inactive") . "'>";
IF (isset($arrEVENTS[gmdate("Y-m-d",$x)])) :
print "<a href=\\"javascript:void(null);\\" onclick=\\"pop_up('details.php?start_date=" . gmdate("Y-m-d", $x) . "');\\">";
ENDIF;
print gmdate("j",$x);
IF (isset($arrEVENTS[gmdate("Y-m-d",$x)])) :
print "</a>";
ENDIF;
print "</td>\
";
if ($dow == 6) : print "</tr>\
"; $rows++; endif;
$x+=86400;
} WHILE ($x <= $EOC and $rows <= 5);
print "<table>";
?>