I've been staring at this for ages and I cant see the problem:
It should output 1,2,3,4 but I get 1,2
I'm losing the 3,4 somewhere but I cant see how as it is added to the array in the loop.
function get_all_items ($category_id_to_search)
{
// returns all item id's of all items in sub-categories into an array
$result1 = mysql_query("SELECT id FROM item WHERE cat_id='$category_id_to_search'");
while ($item_row = mysql_fetch_row($result1))
if ($item_row[0])
{
echo $item_row[0]; // this outputs 1234
$result[]=$item_row[0];
}
$result2 = mysql_query("SELECT id FROM category WHERE parent_id='$category_id_to_search'");
while ($row = mysql_fetch_array($result2))
get_all_items ($row[0]);
return $result;
}
$result = get_all_items ($current_category[0]);
if ($result)
echo $result = implode(",",$result); // this outputs 1,2