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?

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>";
			}
		}

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.