I'm having an issue with below code. I'm trying for some time now, and I believe I must be blind and I do not see something obvious. Can you point at this obvious thing?
Function ought to get all categories and it's names. Takes IDs correctly, but names only for first category and first subcategory.
function collect($id, $current = null) {
global $db_1;
$s = "SELECT category.id as id, category_i18n.name as name from category,category_i18n WHERE category.parent_id= '$id' AND category.visible = '1' AND category_i18n.culture='en' AND category.id = category_i18n.id ORDER BY category.order_asc ASC";
$r = mysql_query($s, $db_1);
$row = mysql_fetch_array($r);
$children = array();
if (mysql_num_rows($r) > 0) {
while ($row) {
$children['name'] = $row['name'];
$children[$row['id']] = collect($row['id']);
}
}
else
{
$children['name'] = $row['name'];
}
return $children;
}
EDIT:
EDIT2:
After changes I'm getting array like this:
array(3) {
["name"]=>
string(9) "Cat"
["id"]=>
string(5) "10404"
["children"]=>
array(3) {
["name"]=>
string(10) "Subcat"
["id"]=>
string(5) "10410"
["children"]=>
bool(false)
}
}
I think it is not problem with mysql query, as in phpmyadmin it works and shows all data properly...