在PHP foreach循环中实现链接

时间:2012-10-30 21:35:37

标签: php mysql

尝试在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>';
}
?>

先谢谢你们的帮助! :)

2 个答案:

答案 0 :(得分:3)

HTML标签的顺序不正确先将li-tag命名为a-tag

  foreach ($values as $value) {
      echo "<li><a href='details.php?id=" . $row['model_id'] . "'>" . $value['bikeName'] . "</a></li>";
    }

答案 1 :(得分:2)

您的ali代码交织在一起:

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

这应该是:

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