php - 如何显示子类别的面包屑

标签 php mysql arrays mysqli

我有一个表结构category_idcategory_nameparent_id来显示多个子类别,现在我需要显示面包屑。

我使用了这个递归函数:

function breadcrump($catid) 
{
  global $con;
  $s = "SELECT id, parent_id FROM category WHERE id = $catid";
  $r = mysqli_query($con,$s);
  $row = mysqli_fetch_object($r);

  if($row->parent_id>='0'){
    $children = $row->id.',';
    breadcrump($row->parent_id);
  }
  $children1 = implode(",",$children);
  return $children1;
}
$result = breadcrump($catid);
print_r($result);

它只显示最后一个 id 的结果,而不是整个数组。 并且 var_dump($result) 显示 null。

最佳答案

我猜你只是保存最后的结果,尝试连接字符串我的意思是$children.=$row->id.','然后进行修剪以删除las

关于php - 如何显示子类别的面包屑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45739396/

相关文章:

php - 从 xml 变量中过滤掉撇号

php - Twitter 解析文本中的方形符号

php - 在预算虚拟主机上运行的好 php 框架?

Javascript - 按一个属性分组,按另一个属性排序

php - CakeDC 用户插件 : How can i install cakedc users plugin, 我已经阅读了文档

mysql - 在不锁定整个表的情况下更改表

php - 将信息从数据库获取到数组

mysql - Elixir 中的 Ecto Migration 究竟是什么?

php - 将数组数据插入 MYSQL/PHP

c++ - 在 C++ 中连接 char 数组(棘手)