I am trying to create a menu using data from a database table. But I have a little problem. The results of my query return a false boolean.
This is my code:
<?php class DataBase { protected $dbUser; protected $dbPassword; protected $dbHost; protected $dbName; protected $db; function __construct() { $this->dbUser = 'root'; $this->dbPassword = ''; $this->dbHost = 'localhost'; $this->dbName = 'ecommercemakup'; $this->db = mysqli_connect($this->dbHost, $this->dbUser, $this->dbPassword, $this->dbName) or die('Fatal error!'); } public function getInstance() { return $this->db; } } ?> <?php $db = new DataBase(); $r = mysqli_query($db->getInstance(), "CALL categories()"); if (mysqli_num_rows($r) > 0) { while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo '<li> <a href=' . $row['name'] . '.php>'; print_r($row['name']); echo '</a> <ul>'; $id = intval($row['idCategory']); $r1 = mysqli_query($db->getInstance(), "CALL subcategories($id)"); if (mysqli_num_rows($r1) > 0) { while ($row1 = mysqli_fetch_array($r1, MYSQLI_ASSOC)) { echo '<li><a href=' . $row1['name'], '.php>'; print_r($row1['name']); echo '</a></li>'; } } echo '</ul></li>'; } } ?>
The first request is executed correctly, but the second request always returns false.
Two procedures:
DELIMITER @@ DROP PROCEDURE categories @@ CREATE PROCEDURE ecommercemakup.categories() BEGIN SELECT * FROM categories; END @@ DELIMITER ; DELIMITER @@ DROP PROCEDURE subcategories @@ CREATE PROCEDURE ecommercemakup.subcategories (IN id_Category INT) BEGIN SELECT idSubcategory, idCategory, name FROM subcategories WHERE idCategory = id_Category; END @@ DELIMITER ;
The categories table contains 2 elements: idCategory and name , and the subcategories table contains 3 elements: idSubcategory , idCategory and name .
Can someone tell me what I'm doing wrong here?
source share