0

Hi every1,
I have a recursive function for building dynamic menu, and it gives me this error:

"Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 261900 bytes)"

Any ideas?

1
Contributor
2
Replies
4
Views
6 Years
Discussion Span
Last Post by Acute
0

my code:

function build_cat_menu()
		{
			$cats = array();
			$this->execute_query("select * from categories group by parentid");
			while($row = $this->sql_res->fetch_assoc())
			{
				$cats[] = array("name"      => $row['name'],
							    "id"        => $row['id'],
							    "parent_id" => $row['parentid']);
			}
			
			$out = "<ul>";
			for($i = 0; $i < sizeof($cats); ++$i)
			{
				if($cats[$i]["parent_id"] == NULL)
				{
					$out.= "<li><a href='#' id=''>".$cats[$i]["name"]."</a>";
					$this->get_childs($out, $cats, $i);
					$out.= "</li>";
				}
			}
			return $out;
		}
		
		function get_childs(&$out, &$cats, $k)
		{
			$nochilds = true;
			for($i = 0; $i < sizeof($cats); ++$i)
			{
				if($cats[$i]["parent_id"] == $k)
				{
					if($nochilds)
						$out.= "<ul>";
					$nochilds = false;
					$out.= "<li><a href='#' id=''>".$cats[$i]["name"]."</a>";
					$this->get_childs($out, $cats, $i);
					$out.= "</li>";
				}
				if(!$nochilds)
					$out.= "</ul>";
			}
		}

Edited by Acute: n/a

0

I've found the bug) I was passing the "$i" in get_childs() instead of $cats[$i]["id"]. Sorry!!!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.