timing out

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
matthiasone
Forum Contributor
Posts: 117
Joined: Mon Jul 22, 2002 12:14 pm
Location: Texas, USA
Contact:

timing out

Post by matthiasone »

ok, when I goto a certain page I get either a blank page that never loads or a time out error. that script as worked before. I call the same function called on this on the previous page. Any ideas what the problem might be?

When I do the get the error it give me a line number which points to an if statement.

Matt
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

show us the code?
sounds like your if statement either falls over or goes into an infinate loop, timing out when the server tells it to sod off
matthiasone
Forum Contributor
Posts: 117
Joined: Mon Jul 22, 2002 12:14 pm
Location: Texas, USA
Contact:

Post by matthiasone »

the calling function:

Code: Select all

$mth = $partsї1] - 2;
  $tyear = $partsї0];
  for($i = 1; $i <= 12; $i++)
  &#123;
	$mth += 1;
    $months&#1111;$i] = make_yrtomth($tyear, $mth, $user, "e");
	if ($mth == 12)
	&#123;
	  $tyear = $tyear + 1;
	  $mth = 0;
	&#125;
  &#125;
the function called (bold where the error is said to be):

Code: Select all

function make_yrtomth($cyear, $mth, $mode)
&#123;
  $first_of_mth = strtotime($mth."/1/".$cyear);
  $day_one = getdate($first_of_mth);
  if ($day_one&#1111;"mon"] == 1)
    $max_days = 31;
  elseif ($day_one&#1111;"mon"] == 2)
  &#123;
    if(checkdate(2, 29, $day_one&#1111;"year"]))
      $max_days = 29;
	else
      $max_days = 28;
  &#125;	  
  elseif ($day_one&#1111;"mon"] == 3)
    $max_days = 31;
  elseif ($day_one&#1111;"mon"] == 4)
    $max_days = 30;
  elseif ($day_one&#1111;"mon"] == 5)
    $max_days = 31;
  elseif ($day_one&#1111;"mon"] == 6)
    $max_days = 30;
  elseif ($day_one&#1111;"mon"] == 7)
    $max_days = 31;
  elseif ($day_one&#1111;"mon"] == 8)
    $max_days = 31;
  elseif ($day_one&#1111;"mon"] == 9)
    $max_days = 30;
  elseif ($day_one&#1111;"mon"] == 10)
    $max_days = 31;
  elseif ($day_one&#1111;"mon"] == 11)
    $max_days = 30;
  elseif ($day_one&#1111;"mon"] == 12)
    $max_days = 31;
  $week = 1;
  $cnt = 1;
  for ($i=0; $i <= 6; $i++)
  &#123;
    if ($i >= $day_one&#1111;"wday"] && $mode == "e")
	&#123;
	  $row1 .= "<td align='center'><font size='2'><a href='staffpage.php?area=form&page=cal&view=day&id=".
	           $day_one&#1111;"year"]."-".$day_one&#1111;"mon"]."-".$cnt."'>".$cnt."</a></font></td>\n";  
      $cnt += 1;
	&#125;
    if ($i >= $day_one&#1111;"wday"] && $mode == "v")
	&#123;
	  $row1 .= "<td align='center'><font size='2'><a href='staffpage.php?area=form&page=cal&view=week&id=".
	           $day_one&#1111;"year"]."-".$day_one&#1111;"mon"]."-".$cnt."'>".$cnt."</a></font></td>\n";  
      $cnt += 1;
	&#125;
	elseif ($i < $day_one&#1111;"wday"])
	  $row1 .= "<td>&nbsp;</td>\n";
  &#125;
  while ($cnt <= $max_days)
  &#123;
    echo"c=".$cnt." md=".$max_days."<BR>";
	$week += 1;
	$temp = "row".$week;
	for ($k=0; $k <= 6; $k++)
    &#123;
      &#1111;b]if ($cnt <= $max_days)&#1111;/b]
	  &#123;
	   	 if ($mode == "e")
		 &#123;
	  	  	$$temp .= "<td align='center'><font size='2'><a href='staffpage.php?area=form&page=cal&view=day&id=".
	           	   	  $day_one&#1111;"year"]."-".$day_one&#1111;"mon"]."-".$cnt."'>".$cnt."</a></font></td>\n";  
      		$cnt += 1;
		 &#125;
		 elseif ($mode == "v")
		 &#123;
	  	  $$temp .= "<td align='center'><font size='2'><a href='staffpage.php?area=form&page=cal&view=week&id=".
	           $day_one&#1111;"year"]."-".$day_one&#1111;"mon"]."-".$cnt."'>".$cnt."</a></font></td>\n";  
      	  $cnt += 1;
	     &#125;
	  &#125;
	  else
	    $$temp .= "<td>&nbsp;</td>\n";
    &#125; 
  &#125; 		    
  for ($j=1; $j <= $week; $j++)
  &#123;
    $temp = "row".$j;
    $body .= "<tr>".$$temp."</tr>\n";
  &#125;
  $month ="<table border='0' cellpadding='3' cellspacing='0'>\n<tr>".	
		  "<td colspan='7' align='center'><font size='2'><b>".$day_one&#1111;"month"].
		  "</b></font></td>\n</tr>\n<tr align='center'>\n<td bgcolor='#256AA3'><font size='2' color='white'>S</font></td>\n".
		  "<td bgcolor='#256AA3'><font size='2' color='white'>M</font></td>\n<td bgcolor='#256AA3'><font size='2' color='white'>T</font></td>\n".
		  "<td bgcolor='#256AA3'><font size='2' color='white'>W</font></td>\n<td bgcolor='#256AA3'><font size='2' color='white'>T</font></td>\n".
		  "<td bgcolor='#256AA3'><font size='2' color='white'>F</font></td>\n<td bgcolor='#256AA3'><font size='2' color='white'>S</font></td>\n</tr>".
		  $body."</table>"; 

  return $month;
&#125;
matthiasone
Forum Contributor
Posts: 117
Joined: Mon Jul 22, 2002 12:14 pm
Location: Texas, USA
Contact:

Post by matthiasone »

ignore the I was trying to bold that line of code. those aren't in the code.

Matt
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

}
else
$$temp .= "<td> </td>\n";
abuot 10 lines below the 'faulty' if statement... try taking a $ off and see what happens

[edit]
Also spotted it several times thru the if statement itself............
[/edit]
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Coco wrote:
}
else
$$temp .= "<td> </td>\n";
abuot 10 lines below the 'faulty' if statement... try taking a $ off and see what happens

[edit]
Also spotted it several times thru the if statement itself............
[/edit]
that shouldn't do it. variable variables.

Code: Select all

$a = "b";
$b = "c";
echo $$a; //should print "c"
zebrax
Forum Newbie
Posts: 16
Joined: Sat Sep 14, 2002 11:39 pm

Post by zebrax »

Ty passing the right number of variables into the function.

Code: Select all

$months&#1111;$i] = make_yrtomth($tyear, $mth, $user, "e");
4 options

function only wants 3

Code: Select all

function make_yrtomth($cyear, $mth, $mode)
matthiasone
Forum Contributor
Posts: 117
Joined: Mon Jul 22, 2002 12:14 pm
Location: Texas, USA
Contact:

Post by matthiasone »

Well, zebrax I never got notification about your post, but I figured it out on my own..........but your were correct...

Matt
Post Reply