Page 1 of 1

Problems with date arrays

Posted: Fri Jan 03, 2003 2:13 pm
by lloydie-t
I am builing a calendar based on a tutorial from web calendar. it seems to be going OK except where there is no records for a month it generates errors saying:
Warning: Wrong datatype for second argument in call to in_array in /var/www/webhosts/web.com/httpdocs/support/desk/calender.php on line 37.
I believe the problem is where there is no records returned for that month either nothing or 0 is being used to compare against the month array. How can I get round this? Do I just use an if/else statement to create a dummy date (ie. 0000-00-00) if a result is not returned? Please find following code.

Code: Select all

<?php 
     include "calender.php"; 
$query = "SELECT dayofmonth(cal_date) as cal_date
FROM cal_entry
WHERE year(cal_date)='$year' and month(cal_date)='$month'"; 

$result = mysql_query ($query); 

while ($row = mysql_fetch_array ($result)) { 

$dateArray[] = $row['cal_date']; 

} 
?>
Calendar function

Code: Select all

<?php
if (in_array($currentDay,$dateArray)) { 
$date = "$year-$month-$currentDay"; 

$calendar .= "<td class='linkedday'> 
<a href='webcal.php?date=$date' 
class='calendarlink'>$currentDay</a></td>"; 

} else { 
$monthday = "$year-$month-$currentDay";
$calendar .= "<td class='day'>
<a href='webcal.php?date=$monthday' 
class='calendarlink'>$currentDay</a></td>"; 

}
?>

Posted: Sat Jan 04, 2003 1:05 am
by volka
a $dateArray = array(); before the while-loop should do

Posted: Sat Jan 04, 2003 1:42 am
by laserlight
hmm... yet the php manual notes "If $arr doesn't exist yet, it will be created. So this is also an alternative way to specify an array."

Posted: Sat Jan 04, 2003 2:58 am
by lloydie-t
thanks volka. All sorted now