1

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! :)

1

2 Answers 2

4

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>";
    }
Sign up to request clarification or add additional context in comments.

Comments

2

Your a and li tags are intertwined:

<a><li>...</a></li>

this should be:

<li><a>...</a></li>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.