I have a static menu with a list of courses, everything is static.
I wish only the courses that are active are displayed on the menu, I want to take the same order.
I have all the content of submenus in a variable, if active in the DB is displayed and if not active is not displayed.
I'm learning and I want to do it the right way possible.
But this code does not work yet. Could someone help me?
<?php
//conexion DB
$dbLink = new PDO('mysql:host=localhost;dbname=dbname;charset=utf8', 'username', 'password', [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);
//array for order
$coursesarr = array('spanish', 'english', 'latin');
//query mysql
$qry_courses = "SELECT `shortname`, `visible` FROM `courses` WHERE visible = 1";
//define static varibles
$spanish = '<li><a href="/spanish.html">spanish</a>
<ul>
<li>task 1 select course</li>
<li>task 2 select course</li>
<li>task 3 select course</li>
...
</ul></li>';
$english = '<li><a href="/english.html">English</a>
<ul>
<li>task 1 select course</li>
<li>task 2 select course</li>
<li>task 3 select course</li>
...
</ul></li>';
$latin = '<li><a href="/latin.html">Latin</a>
<ul>
<li>task 1 select course</li>
<li>task 2 select course</li>
<li>task 3 select course</li>
...
</ul></li>';
//PDO execute
$stmt = $dbLink->prepare($qry_courses);
$stmt->execute();
//Generate query DB and create menu
echo '<nav><ul>';
while($row_courses = $stmt->fetchAll(PDO::FETCH_ASSOC)) {
if(in_array("$row_courses['shortname']", $coursesarr){
echo $.'$row_courses['shortname']'.;
}
}
echo '<ul><nav>';
?>
Thank you