I am only able to echo the first selectbox but not the sub category. I checked the code for syntax errors and there were none found. I am guessing the logic is incorrect. Can anyone tell me Why is it not displaying the subcategories select box ?
<?php
$dbh = new PDO("mysql:host=" . $host . ";dbname=" . $db, $user, $pass);
if(isset($_GET["category"]) && is_numeric($_GET["category"]))
{
$category = $_GET["category"];
}
?>
<form name="theForm" method="get">
<!-- Category SELECTION -->
<select name="category" size="6" onChange="autoSubmit();">
<?php
$categories = $dbh->query('SELECT * FROM category ORDER BY c_id');
while ($row = $categories->fetch()) {
echo '<option value="' . $row['c_id'] . '"';
if ($row['c_id'] == $category) echo ' selected';
echo '>' . htmlentities($row['category']);
}
?>
</select>
<br><br>
</form>
Your query is most likely returning 0 results due to your use of a variable inside of a string using single quotes.
Use double quotes around your query, or concatenate the value like
'... c_id = ' . $categoryBut even better than that, learn how to use parameterized queries and bind the values instead.