Retrieving ids from MySQL query
Posted
by
Matt Maclennan
on Stack Overflow
See other posts from Stack Overflow
or by Matt Maclennan
Published on 2012-11-01T10:59:08Z
Indexed on
2012/11/01
11:00 UTC
Read the original article
Hit count: 230
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>';
}
?>
© Stack Overflow or respective owner