Retrieving ids from MySQL query
- by Matt Maclennan
I am having trouble accessing the "model_id" and "brand_id" from the foreach loop that I am using.
They are the right field names, because I have echoed them successfully, and I have also "var_dumped" the array, and the IDs are there. It is just a case of implementing the relevant links on each list section. Below is the code I have.
<?
$output = mysqli_query("SELECT * FROM bikes, bikeTypes WHERE bikes.model_id = bikeTypes.model_id");
$result = array();
while($row = mysqli_fetch_array($output))
{
$result[$row['model']][] = $row;
}
foreach ($result as $category => $values) {
echo "<li><a href='test.php?id=" . $row['model_id'] . "'>".$category.'</a><ul>';
foreach ($values as $value)
{
echo "<li><a href='details.php?id=" . $row['brand_id'] . "'>" . $value['bikeName'] . "</a></li>";
}
echo '</ul>';
echo '</li>';
}
?>