I'm trying to add the ability to list multiple events per day using this code:
Code: Select all
$result2 = mysql_query("SELECT * FROM `CAL_SCHED` WHERE `SCHED_DATE` ='$schedDate' AND `SCHED_EMP_ID` = 1");
if(mysql_num_rows($result2) > 0) {
while ($row = mysql_fetch_array($result2)) {
if ($schedDate = $row['SCHED_DATE']) {
$p_name = $row["SCHED_PT_NAME"];
$p_id = $row["SCHED_PT_ID"];
$pt_list.= "<a href=\"$p_id\" class=\"calLink\">$p_name</a><br />";
}
}
$xml.="<div class='calevent'>$pt_list</div>";
}I'm pretty sure the error is in the way I'm handling the array, and it's probably something relatively simple. I've been staring at this for days and I think I might be too far in the forest to see the trees.
Thanks in advance for any help.
For reference, here's the full code for the calendar itself:
Code: Select all
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-Type: text/xml; charset=utf-8");
include('config.php');
$xml = '<?xml version="1.0" ?><response><content><![CDATA[';
if($_GET['event'] != '') {
$fields = explode("-",$_GET['event']);
$result = mysql_query("SELECT *,DATE_FORMAT(`SCHED_DATE`,'%b %e, %Y') as thedate,DATE_FORMAT(`SCHED_DATE`,'%c') as themonth,DATE_FORMAT(`SCHED_DATE`,'%Y') as theyear FROM `CAL_SCHED` WHERE YEAR(`SCHED_DATE`) = ".$fields[0]." AND MONTH(`SCHED_DATE`) = ".$fields[1]." AND DAYOFMONTH(`SCHED_DATE`) = ".$fields[2]." ORDER BY `SCHED_ID` ASC");
$result_test = print_r($result);
$i = 0;
while($row = mysql_fetch_array($result)) {
$xml .= "<div id='event'";
if($i < (mysql_num_rows($result)-1)) $xml .= " style='border-bottom:none'";
$xml .= "><div class='heading'><div class='title'>".$row['heading']."</div><div class='posted'>".$row['thedate']."</div>";
if($i == 0) $xml .= "<div class='back'><a href='javascript:navigate(".$row['themonth'].",".$row['theyear'].",\"\")'>Return to calendar</a></div>";
$xml .= "</div><div class='line'>".$row['body']."</div><br /></div><br />";
$i++;
}
} else {
$month = $_GET['month'];
$year = $_GET['year'];
if($month == '' && $year == '') {
$time = time();
$month = date('n',$time);
$year = date('Y',$time);
}
$date = getdate(mktime(0,0,0,$month,1,$year));
$today = getdate();
$hours = $today['hours'];
$mins = $today['minutes'];
$secs = $today['seconds'];
if(strlen($hours)<2) $hours="0".$hours;
if(strlen($mins)<2) $mins="0".$mins;
if(strlen($secs)<2) $secs="0".$secs;
$days=date("t",mktime(0,0,0,$month,1,$year));
$start = $date['wday']+1;
$name = $date['month'];
$year2 = $date['year'];
$offset = $days + $start - 1;
if($month==12) {
$next=1;
$nexty=$year + 1;
} else {
$next=$month + 1;
$nexty=$year;
}
if($month==1) {
$prev=12;
$prevy=$year - 1;
} else {
$prev=$month - 1;
$prevy=$year;
}
if($offset <= 28) $weeks=28;
elseif($offset > 35) $weeks = 42;
else $weeks = 35;
$xml .= "<div id='tableheader'><a href='javascript:navigate($prev,$prevy,\"\")' title='Prev Month'>«</a> $name $year2 <a href='javascript:navigate($next,$nexty,\"\")' title='Next Month'>»</a>
</div><table class='cal' cellpadding='0' cellspacing='0'>
<tr class='dayhead'>
<td>Sun</td>
<td>Mon</td>
<td>Tue</td>
<td>Wed</td>
<td>Thu</td>
<td>Fri</td>
<td>Sat</td>
</tr>";
$col=1;
$cur=1;
$next=0;
for($i=1;$i<=$weeks;$i++) {
if($next==3) $next=0;
if($col==1) $xml.="\n<tr class='dayrow'>";
$xml.="\t<td valign='top' onMouseOver=\"this.className='dayover'\" onMouseOut=\"this.className='dayout'\">";
if($i <= ($days+($start-1)) && $i >= $start) {
$xml.="<div class='day'><b";
if(($cur==$today[mday]) && ($name==$today[month]) && ($year2==$today[year])) $xml.=" class='today_cal'";
$xml.=">$cur</b></div>";
if ($cur < 10) {
$cur2 = "0" . $cur;
}
else {
$cur2 = $cur;
}
if ($month < 10) {
$month2 = "0" . $month;
}
else {
$month2 = $month;
}
$schedDate = $year2.'-'.$month2.'-'.$cur2;
$result2 = mysql_query("SELECT * FROM `CAL_SCHED` WHERE `SCHED_DATE` ='$schedDate' AND `SCHED_EMP_ID` = 1");
if(mysql_num_rows($result2) > 0) {
while ($row = mysql_fetch_array($result2)) {
if ($schedDate = $row['SCHED_DATE']) {
$p_name = $row["SCHED_PT_NAME"];
$p_id = $row["SCHED_PT_ID"];
$pt_list.= "<a href=\"$p_id\" class=\"calLink\">$p_name</a><br />";
}
}
$xml.="<div class='calevent'>$pt_list</div>";
}
$xml.="\n\t</td>\n";
$cur++;
$col++;
} else {
$xml.=" \n\t</td>\n";
$col++;
}
if($col==8) {
$xml.="\n</tr>\n";
$col=1;
}
}
$xml.="</table><div id='tablefooter'><a href='javascript:navigate(\"\",\"\",\"\")'>Today »</a></div>";
}
$xml .= "]]></content></response>";
echo $xml;
?>