在 PHP foreach 循环中实现链接 [英] Implementing link in PHP foreach loop

查看:61
本文介绍了在 PHP foreach 循环中实现链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

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

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>";
    }

这篇关于在 PHP foreach 循环中实现链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆