1

试图在我的 foreach 循环中实现链接。但是,无法使 $category 链接正常工作。任何指针?设法使链接适用于子类别,如下所示:

<?
$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>';
}
?>

提前感谢您的帮助!:)

4

2 回答 2

4

HTML 标签的顺序不正确,首先是 li-tag,然后是 a-tag

  foreach ($values as $value) {
      echo "<li><a href='details.php?id=" . $row['model_id'] . "'>" . $value['bikeName'] . "</a></li>";
    }
于 2012-10-30T21:38:05.830 回答
2

你的ali标签是交织在一起的:

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

这应该是:

<li><a>...</a></li>
于 2012-10-30T21:39:25.723 回答