I'm trying to automatically populate a navigation menu based on available categories in the database. As follows is my code:
<?php
$sidenav = query("SELECT cat_id, cat_name FROM prod_cat ORDER By cat_name LIMIT 20");
if ($sidenav != false)
{
$sidenav->execute();
while($result = $sidenav->fetch(PDO::FETCH_BOTH))
{
echo "<div class='left_button'><a href='/customcms/products/index.php?page=list-product&category={$result['cat_id']}'>{$result['cat_name']}</a></div>";
}
}
?>
However, the code "$sidenav->execute();" gives the following error message: "Fatal error: Call to a member function execute() on a non-object on line ...".
Note: Please, be advised that "query" is a custom function and I'm connecting to the database via PDO.
Your help would be much appreciated, as always.