Fatal error: Allowed memory size

error on some pages, but not others with same setup

Page 1 of 1

1 Replies - 658 Views - Last Post: 03 September 2009 - 06:28 PM Rate Topic: -----

#1 noname_clark  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 75
  • Joined: 22-October 08

Fatal error: Allowed memory size

Posted 03 September 2009 - 05:14 PM

Hi guys,
I'm getting a weird error, I know what it means, but I don't know why it's happening.

I'm creating a calendar page, and basically, calendar.php gets the month and year from the string (ex. calendar.php?month=September&year=2009) and then matches it into a cell in the database to find out what spot the first day of the month is on (if 1st of the month is on a Sunday, the spot is 1, Monday is 2, etc.) I called this variable $start.

The weird thing is that the Allowed memory size error randomly happens... I can't find the one source of the problem. I can go to one calendar and it works perfectly, and then going to the next month and it won't work. It seems to be the same in all browsers (eg. december 2017 doesn't work in IE, FireFox, or Chrome).

here is the error I receive:
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 24 bytes) in /home6/wetsoxor/public_html/shazbots/calendar.php on line 68

line 68 is at the end of the code, and I marked it.

$sql = "SELECT * FROM `calendar_start` WHERE `month` = '".$month."' AND `year` = '".$year."' LIMIT 1";
$sql=mysql_query($sql,$conn) or die(mysql_error());
$cal_exist = mysql_num_rows($sql);
while ($newArray=mysql_fetch_array($sql))
	 	{
$start=$newArray['start'];
		} 
$daystart=$start;	
$daystart--;

//get the number of days in each month
if ($month == 'January'){$daysinmonth='31';}
else if($month == 'February'){
	if ($leap == '1'){$daysinmonth='29';}
	else {$daysinmonth='28';}}
else if($month == 'March'){$daysinmonth='31';}
else if($month == 'April'){$daysinmonth='30';}
else if($month == 'May'){$daysinmonth='31';}
else if($month == 'June'){$daysinmonth='30';}
else if($month == 'July'){$daysinmonth='31';}
else if($month == 'August'){$daysinmonth='31';}
else if($month == 'September'){$daysinmonth='30';}
else if($month == 'October'){$daysinmonth='31';}
else if($month == 'November'){$daysinmonth='30';}
else if($month == 'December'){$daysinmonth='31';}	
$m=$daysinmonth;


$a=1; //STARTS WITH SPAN #1, meaning $img[0] HAS NO DEFINITION

$start--; //because calendar_start table makes sunday = 1, when there should not be a gray block on sunday

while ($start!=0){
	$img[$a]="calendar/grey.jpg"; //cells before the 1st day of the month starts (colored grey)
	$a++;
	$start--;
	$spansleft--;
	}	

while ($daysinmonth != 0){
	$img[$a]="calendar/yellow.jpg"; //default cell color for the days (yellow)
	$a++;
	$spansleft--;
	$daysinmonth--;
	}

while ($spansleft != 0){
	   //NEXT LINE IS NUMBER 68
	$img[$a]="calendar/grey.jpg"; //cells after the last day of the month starts (colored grey) //THIS IS LINE NUMBER 68
	   //PREVIOUS LINE IS NUMBER 68
	$a++;
	$spansleft--;
	}





any help to make this work with any month? Maybe make the code tighter in some way to make the chance of this less?

Is This A Good Question/Topic? 0
  • +

Replies To: Fatal error: Allowed memory size

#2 noname_clark  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 75
  • Joined: 22-October 08

Re: Fatal error: Allowed memory size

Posted 03 September 2009 - 06:28 PM

I solved it.

$spansleft was less than 0, so it was stuck in a while loop causing it to crash.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1