This is probably a stupid question, please bare with me 🙂
I have been working on an events calendar script for a couple months and I finally got it working. I want to "include" it on my home page, which was easy...I just put the code: include('http://www.mysite.com/calendar/cal_show.php');
on my page and it was perfect. The problem is that when I click on the "next" button, it takes me to the next month, but on a page that is ONLY the calendar. I want it to remain on the home page, but have the months move forward.
Does that make sense at all? Can anyone tell me where I went wrong?
Here is my calendar script (it's called 'cal_show.php'):
<?php
$ev_dat = array();
for ($i=0;$i<32;$i++) {
$ev_dat[$i]=0;
}
$now = date("Y-m-d", time());
list($ty, $tm, $td) = explode('-',$now); // ty=thisyear, etc. used for highlighting 'today'
include("cal_parms.php"); // assorted configuration variables
include($dat_names); // retrieved from cal_parms.php as a 'language' file
if (!isset($_GET['m'])) {
$m = date("m",mktime());
} else {
$m = $_GET['m'];
}
if (!isset($_GET['y'])) {
$y = date("Y",mktime());
} else {
$y = $_GET['y'];
}
/*== get what weekday the first is on ==*/
$tmpd = getdate(mktime(0,0,0,$m,1,$y));
$month = $tmpd["month"];
$firstwday= $tmpd["wday"];
$lastday = mk_getLastDayofMonth($m,$y);
/*== get the last day of the month ==*/
function mk_getLastDayofMonth($mon,$year)
{
for ($tday=28; $tday <= 31; $tday++)
{
$tdate = getdate(mktime(0,0,0,$mon,$tday,$year));
if ($tdate["mon"] != $mon)
{
break;
}
}
$tday--;
return $tday;
}
// compute range of dates for this month to match dates in database in the format yyyy-mm-dd
if (strlen($m)<2) {
$q="0";
$q.=$m;
}
else {
$q = $m;
}
$dats_beg = $y. "-". $q. "-01";
$dats_en = $y. "-". $q. "-". $lastday;
// open db conn and select all records where date is between $dats_beg and $dats_en
include("cal_db_conn.php");
mysql_connect($db_host, $db_login, $db_pass) or die ("Can't connect!");
mysql_select_db($db_name) or die ("Can't open database!");
$query = "SELECT * FROM $db_table WHERE (ev_dat>='$dats_beg') AND (ev_dat<='$dats_en') ";
$result = mysql_db_query($db_name, $query);
// any matches?
if ($result)
{
// handle the matches and pass relevant info to arrays
while ($myrow = mysql_fetch_array($result))
{
$found = $myrow['ev_dat'];
$pieces = explode("-", $found);
$dd = intval($pieces[2]);
$ev_dat[$dd] = $myrow['id'];
}
}
?>
<table cellpadding="1" cellspacing="1" border="0" bgcolor="#ffffff" class="white">
<tr><td colspan="7" bgcolor="#003366">
<table cellpadding="1" cellspacing="1" border="0" width="100%">
<tr bgcolor="#003366" class="white"><th width="25"><a href="<? echo $_SERVER['PHP_SELF']; ?>?m=<?=(($m-1)<1) ? 12 : $m-1 ?>&y=<?=(($m-1)<1) ? $y-1 : $y ?>"><img src='calendar/images/prev.gif' height='18' width='18' alt='' border='0' /></a></th>
<th >
<?php
echo "<a href='http://www.mysite.com/calendar/show-month.php?mon=". $m. "&yr=". $y. "'>";
echo "<span style='text-decoration:none'>". $mo[intval($m)]. " ". $y. "</span></a>";
?>
</th>
<th width="25"><a href="<? echo $_SERVER['PHP_SELF']; ?>?m=<?=(($m+1)>12) ? 1 : $m+1 ?>&y=<?=(($m+1)>12) ? $y+1 : $y ?>"><img src='calendar/images/next.gif' height='18' width='18' border='0' alt='' /></a></th>
</tr>
</table>
</td></tr>
<tr bgcolor="#003366" class="white">
<th width="25"><? echo $da[1]; ?></th>
<th width="25"><? echo $da[2]; ?></th>
<th width="25"><? echo $da[3]; ?></th>
<th width="25"><? echo $da[4]; ?></th>
<th width="25"><? echo $da[5]; ?></th>
<th width="25"><? echo $da[6]; ?></th>
<th width="25"><? echo $da[7]; ?></th>
</tr>
<?
$d = 1;
$wday = $firstwday;
$firstweek = true;
/*== loop through all the days of the month ==*/
while ( $d <= $lastday)
{
/*== set up blank days for first week ==*/
if ($firstweek)
{
if ($wday!=0) {
echo "<tr bgcolor='#cccccc' class='white'>\n";
for ($i=1; $i<=$firstwday; $i++) {
echo "<td bgcolor='#cccccc' class='white'> </td>\n";
}
}
/*== Sunday start week with <tr> ==*/
else {
echo "<tr bgcolor='#cccccc' class='white'>\n";
}
$firstweek = false;
}
/*== check for event ==*/
echo "<td ";
// is this day 'today' AND there's no event today
if (($ty==$y) && ($tm==$m) && ($td == $d) && (!$ev_dat[$d])) {
echo "bgcolor='#cccccc' class='white'>". $d;
}
elseif ($ev_dat[$d]) {
// get what's happening that day and use as 'mouseOver' for the link
$query = "SELECT * FROM $db_table WHERE id=$ev_dat[$d] ";
$result = mysql_query($query);
$ev = mysql_fetch_array($result);
$titl = $ev['ev_title'];
switch ($ev['ev_category'])
{
case 'Home':
$color='006633';
break;
case 'Road':
$color='990000';
break;
case 'event':
$color='003366';
break;
default:
$color='cccccc';
}
echo "bgcolor=\"$color\">";
$url = "http://www.mysite.com/calendar/show.php?event=". $ev_dat[$d]. "&sho=". $win_sho;
if ($win_sho=="1") {
echo "<a href='javascript:winy(\"". $url."\")' title=\"". $titl. "\">". $d. "</a>";
}
else {
echo "<a href='". $url. "' title=\"". $titl. "\">". $d. "</a>";
}
}
else {
echo "bgcolor='#cccccc'>". $d;
}
echo "</td>\n";
/*== Saturday end week with </tr> ==*/
if ($wday==6) {
echo "</tr>\n";
}
$wday++;
$wday = $wday % 7;
if (($wday==0) AND ($d!=$lastday)){ echo "<tr bgcolor='#cccccc' class='white'>\n"; }
$d++;
}
// and close off the table
if (($wday!=7) AND ($wday!=0)) {
for ($i=$wday; $i<=6; $i++) {
echo "<td bgcolor='#cccccc' class='white'> </td>\n";
}
echo "</tr>";
}
echo "\n</table>";
include("win_open.php");
?>