• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

Whats wrong with my nexted for loops?

Hi, I created a while loop with a for loop inside of it:

		while($rows = mysql_fetch_array($result)) {
			
				$output .= "<input type=\"checkbox\" name=\"materials[]\" value=\"" . $rows['id'] . "\" ";
				for($i = 0; $i <= count($materials)-1; $i++) {
					if($materials[$i] == $rows['id'] && !empty($rows['type'])) {
						$output .= "checked ";
					}
				}
			$output .=  "/>" . $rows['type'] . "<br />";
		
		}

Open in new window


which worked as planned till I added another for loop:

		while($rows = mysql_fetch_array($result)) {
			for($i = 0; $i <= 15; $i++) {
				$output .= "<input type=\"checkbox\" name=\"materials[]\" value=\"" . $rows['id'] . "\" ";
				for($i = 0; $i <= count($materials)-1; $i++) {
					if($materials[$i] == $rows['id'] && !empty($rows['type'])) {
						$output .= "checked ";
					}
				}
			$output .=  "/>" . $rows['type'] . "<br />";
			}
		}

Open in new window


Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 16252913 bytes)

Anyone know the meaning of this??
0
FairyBusiness
Asked:
FairyBusiness
1 Solution
 
Greg AlexanderLead DeveloperCommented:
Well, it was basically in an endless loop. change the innerl loops variable to j and it should work

<?
 while($rows = mysql_fetch_array($result)) {
		for($i = 0; $i <= 15; $i++) {
				$output .= "<input type=\"checkbox\" name=\"materials[]\" value=\"" . $rows['id'] . "\" ";
				for($j = 0; $j <= count($materials)-1; $j++) {
						if($materials[$j] == $rows['id'] && !empty($rows['type'])) {
								$output .= "checked ";
						}
				}
		$output .=  "/>" . $rows['type'] . "<br />";
		}
}
?>

Open in new window

0
 
FairyBusinessAuthor Commented:
Thanks!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now