Jump to content

Event Calendar Help


shazman

Recommended Posts

I've created the calendar by following this tutorial.

I created a MySQL table like this:

id

text

month

day

year

1

This is an event!

3

12

2008

1

This is another event!

3

4

2008

 

This is how I'm accessing the data from the table:

$getEventsQuery = mysql_query("SELECT * FROM `calendar`") or die(mysql_error());
$eventResult = mysql_fetch_array($getEventsQuery);

 

Here is my script:

<?php
//Set the variabels
$today				=			getdate();
$time				=			date("g:i");
$firstDay			=			getdate(mktime(0,0,0,$today['mon'],1,$today['year']));
$lastDay			=			getdate(mktime(0,0,0,$today['mon']+1,0,$today['year']));

//Create the table
print '<table width="770" border="1" cellpadding="0" cellspacing="0" align="center">' . "\r";
print "  <tr>\r    <td colspan=\"7\" class=\"monthHeader\">$today[month] - $today[year]</td>\r  </tr>\r";
print "  <tr class=\"dayWords\">\r    <td>Sunday</td>\r
    <td>Monday</td>\r
    <td>Tuesday</td>\r
    <td>Wednesday</td>\r
    <td>Thursday</td>\r
    <td>Friday</td>\r
    <td>Saturday</td>\r  </tr>\r";
print "  <tr class=\"dayNumbers\">\r";
//Creat blank spaces in begining if any
for($i=0;$i<$firstDay['wday'];$i++)
{
print "    <td height=\"80\" width=\"110\" valign=\"top\"> </td>\r";
}
//Number the days starting after blank spaces
$day = 0;
for($i=$firstDay['wday'];$i<7;$i++)
{
$day++;
if ($day == $today['mday']){
	$style = ' class="actday"';
	$text = ' - Today';}
else{
	$style = '';
	$text = '';}
if ($eventResult['day'] == $day){
	$event = " - <a href=\"events.php?action=read&id=$eventResult[id]>Event</a>";}
else{
	$event = '';}
print "    <td height=\"80\" width=\"110\" valign=\"top\"$style>$day$text$event</td>\r";
}
print "  </tr>\r";
//fill in the weeks after first and before last.
$weeks = floor(($lastDay['mday'] - $day) / 7);
for($i=0;$i<$weeks;$i++)
{
print "  <tr class=\"dayNumbers\">\r";
for($j=0;$j<7;$j++)
{
	$day++;
	if ($day == $today['mday']){
		$style = ' class="actday"';
		$text = ' - Today';}
	else{
		$style = '';
		$text = '';}
	if ($eventResult['day'] == $day){
		$event = " - <a href=\"events.php?action=read&id=$eventResult[id]>Event</a>";}
	else{
		$event = '';}
	print "    <td height=\"80\" width=\"110\" valign=\"top\"$style>$day$text$event</td>\r";
}
print "  </tr>\r";
}
//fill in last row
if($day < $lastDay['mday'])
{
print "  <tr class=\"dayNumbers\">\r";
for($i=0;$i<7;$i++)
{
	$day++;
	if ($day == $today['mday']){
		$style = ' class="actday"';
		$text = ' - Today';}
	else{
		$style = '';
		$text = '';}
	if ($eventResult['day'] == $day){
		$event = " - <a href=\"events.php?action=read&id=$eventResult[id]>Event</a>";}
	else{
		$event = '';}
	if ($day <= $lastDay['mday']){
		print "    <td height=\"80\" width=\"110\" valign=\"top\"$style>$day$text$event</td>\r";}
	else{
		print "    <td height=\"80\" width=\"110\" valign=\"top\"$style> </td>\r";}
}
print "  </tr>\r";
}
print "</table>\r";
?>

 

Now, the problem that I'm having is getting the days which have events on them to display the link to read the event. The event for day 12 shows up but not day 4.

 

 

Link to comment
https://forums.phpfreaks.com/topic/95718-event-calendar-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.