I am currently creating a MySQLi PHP forum, and i'm having some problems with the MySQL LEFT JOINs, i am trying to get all the subforums "joined" with the set catid,
the query itself works fine when testing it in mysql workbench, and i receive the correct list. but whenever i try to put the results into an array, i get null
My current codelooks like this
$sql = 'SELECT `c`.`id`, `c`.`name`, `sc`.`id_sub`, `sc`.`name_sub`, `sc`.`catid`
FROM `forum_categories` AS `c`
LEFT JOIN `forum_subcategories` AS `sc`
ON `c`.`id` = `sc`.`catid`';
$stmt = $mysqli->query($sql);
$forum_categories = array();
while($row = $stmt->fetch_array(FETCH_ASSOC))
{
// define forum category
$forum_categories[$row['id']] = array(
'title' => $row['name'],
);
// add forums to category
$forum_categories[$row['id']]['forum_subcategories'][] = array(
'id' => $row['id_sub'],
'title' => $row['name_sub']
);
}
var_dump ($row->name);
But the var_dump just returns null.
This is what the var_dump($stmt); returns
object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(5) ["lengths"]=> NULL ["num_rows"]=> int(10) ["type"]=> int(0) }