I am working on my first App. Basically, I am trying to integrate a Navigation menu that I have used outside Codeigniter. In a normal PHP app, I have the query as follows (the DB constants and connection are in an includes.php file:
//Table columns: id, page, parent
// Select all from the menu table
// Define database connection constants
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASSWORD', 'somepassword');
define('DB_NAME', 'dropdown_menu');
if (!isset($dbc)){
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (!$dbc) {
die("Database connection and selection failed: " . mysqli_error());
}
}
//$result=mysqli_query("SELECT id, label, link, parent FROM menu ORDER BY parent, sort, label");
$query = "SELECT id, label, parent FROM tree_menu ORDER BY parent, id";
$result = mysqli_query($dbc, $query)
or die('Error querying database.');
From that stage, I need to feed the $results variable to mysqli_fetch_assoc() and process things using a while loop, as follows:
while ($items = mysqli_fetch_assoc($result)) {
//some code
}
In codeigniter I can't seem to get results from MySQL in a format equivalent to $results obtained from the above query. I did a var_damp($results), so that I see exactly what $results looks like. This is what I get:
object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(3) ["lengths"]=> NULL ["num_rows"]=> int(13) ["type"]=> int(0) }
I tried returning an object() but it did not work because it does not return an equivalent of mysqli_result which I need to use to generate an hierarchical navigation menu.
My question is: Is it possible to that kind of object in Codeigniter - mysqli_result equivalent?
Any help will be deeply appreciated.