Jump to content

dynamic php calandar broken


patcouch22

Recommended Posts

Hello,

 

I'm new to these forums and I joined because I am having some problems with a dynamic calendar that I am trying to get working.

 

The error I am receiving is the following: "Fatal error: Maximum execution time of 30 seconds exceeded in /home/rzbqplmx/public_html/phpFunctions.php on line 135".  This much I understand... I have and infinite loop, or my code is really really inefficient.

 

My Goal is to create a javascript function call for each event in my database of events, the function call should look something like this : "DefineEvent(20070501, "test", "events.php?id=4", "","" ,"" );"

 

and it does until I have the event stretch between 2 months.  here is my code:

 

function checkDateOutput($year, $month, $day){

switch($month){

case '01':

if ($day > 31){

$day = '01';

$month = '02';

}

break;

case '02':

if ($day > 28){

$day = '01';

$month = '03';

}

break;

case '03':

if ($day > 31){

$day = '01';

$month = '04';

}

break;

case '04':

if ($day > 30){

$day = '01';

$month = '05';

}

break;

case '05':

if ($day > 31){

$day = '01';

$month = '06';

}

break;

case '06':

if ($day > 30){

$day = '01';

$month = '07';

}

break;

case '07':

if ($day > 31){

$day = '01';

$month = '08';

}

break;

case '08':

if ($day > 31){

$day = '01';

$month = '09';

}

break;

case '09':

if ($day > 30){

$day = '01';

$month = '10';

}

break;

case '10':

if ($day > 31){

$day = '01';

$month = '11';

}

break;

case '11':

if ($day > 30){

$day = '01';

$month = '12';

}

break;

case '12':

if ($day > 31){

$day = '01';

$month = '01';

$year++;

}

break;

}

//return ($year.$month.$day);

}

$rs = mysql_query( "select * from events" );

$list = '';

 

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

#formats the date

$date = $row["eventDate"];

$enddate = $row['enddate'];

$year = substr($date, 0, 4);

$month = substr($date, 5, 2);

$day = substr($date, 8);

$day--;

$enddate = substr($enddate, 0, 4) . substr($enddate, 5, 2) . substr($enddate, 8);

 

#generates the function for each event

do {

$day++;

if ($day < 10)

{

$day = '0'.$day;

}

checkDateOutput($year, $month, $day);

$year = substr($date, 0, 4);

$month = substr($date, 5, 2);

$day = substr($date, 8);

$list .= "DefineEvent(".$year. $month. $day;

$list .= ", \"".$row["name"];

$list .= "\", \"events.php?id=".$row['id']."\", \"\",\"\" ,\"\" );";

}while(($year.$month.$day) <= $enddate);

}

 

 

Thank you very much.  if you would like to take a look at the page you can find it at overdriveonline.org/calendar.php

 

 

~pat

Link to comment
https://forums.phpfreaks.com/topic/46963-dynamic-php-calandar-broken/
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.