Reputation: 1304
Trying to implement links in my foreach loop. However, can't get the $category link working. Any pointers? Managed to get the link to work for the sub-category, as shown below:
<?
$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>".$category.'<ul>';
foreach ($values as $value) {
echo "<a href='details.php?id=" . $row['model_id'] . "'><li>" . $value['bikeName'] . "</a></li>";
}
echo '</ul>';
echo '</li>';
}
?>
Thanks for the help in advance guys! :)
Upvotes: 1
Views: 2461
Reputation: 74038
Your a
and li
tags are intertwined:
<a><li>...</a></li>
this should be:
<li><a>...</a></li>
Upvotes: 2
Reputation: 2939
The HTML Tags are not in the correct order first commes the li-tag and then the a-tag
foreach ($values as $value) {
echo "<li><a href='details.php?id=" . $row['model_id'] . "'>" . $value['bikeName'] . "</a></li>";
}
Upvotes: 4