View Full Version : Problems with PHP Calendar

03-09-2007, 10:44 AM
Hi there,

I'm having trouble with a PHP calendar script I'm trying to create for my new employers. Basically, users enter events via a script and then the calendar dynamically displays the events on the particular date, and provides a link to the full details of the event. However, I'm having trouble getting the calendar to display all the events. I can get it to display one, but I'm having a bit of a mental block in terms of how to get the rest to display. This is where you magical, wonderful, brilliant people swoop in to save the day

Here is a code segment:

php:for( $counter = 1; $counter <= $numdaysinmonth; $counter ++ )

$rowcounter ++;

$dayVal = $getEventArray['evtDay'];
$dayQuery = "SELECT evtName FROM event_table WHERE evtDay = '$dayVal'";
$dayResult = mysql_query($dayQuery) or die ("Problem with query: " . mysql_query());
$dayArray = mysql_fetch_array($dayResult) or die ("Problem with fetch: " . mysql_query());
if($dayVal == $initial)
$task = $dayArray['evtName'];
printf("This is a test: %s ", $dayVal);
elseif($dayVal != $initial)
$task = "";

printf("tt<td>%s - %s</td>n", $counter, $task);
$initial ++;
printf("Last DayVal = %s", $getEventArray['dayVal']);
print("this is the else");
echo "tt<td>$counter</td>n";

The full code is here: www.andyseaton.co.uk/testCalendar.txt

and a sample of the working calendar: www.andyseaton.co.uk/testCalendar.php

Basically, what I want is the counter to increment through the days of the month, and if it hits any of the values in the array (which is taken from the events table) it prints both the day number and the event details.

so if there were three events from the month of march, on the 12th, 14th and 21st, for example, the array values would be {12, 14, 21} I can get the first one to display, as shown in the calendar just now, but I cannot get it to iterate to the next value in the array. I have tried to use next() and each() but those do not seem to work.

I would appreciate any light that people could shed on this issue.



03-10-2007, 05:27 AM
I don;t know exactly how you are getting your days, months, and years, but are you looking for something like this:

$dayArray = array(1,2,3,4,5,6,7,8,9,10,....);

foreach ($dayArray as $val)
echo "<p><b>$month $val, $year</b>";

$query = "SELECT evtName FROM event_table WHERE evtDay='$val' AND evtMonth='$month' AND evtYear='$year'";
$result = mysql_query($query) or die ("Problem with query: " . mysql_query());
if (mysql_num_rows($result) >= 1)
while ($row = mysql_fetch_assoc($result))
echo "<br />".$row['evtName'];

echo "</p>";