Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在菜单上显示子类别_Php_Mysql_Categories - Fatal编程技术网

Php 在菜单上显示子类别

Php 在菜单上显示子类别,php,mysql,categories,Php,Mysql,Categories,我的分类表如下所示: id - title - sub *如果sub为0,则表示它是主类别 通过下面的代码,我可以列出我的主要分类,如 主要1 主要2 主要3 这是代码 <?php function menucategories() { include ('connect.php'); $q=mysql_query("select * from categories where sub='0' order by asc"); while ($r=mysql_fetch_ar

我的分类表如下所示:

id - title - sub
*如果sub为0,则表示它是主类别

通过下面的代码,我可以列出我的主要分类,如

  • 主要1
  • 主要2
  • 主要3
这是代码

  <?php

function menucategories() {
include ('connect.php');

$q=mysql_query("select  * from categories where sub='0' order by asc");
while ($r=mysql_fetch_array($q))

    echo "<a class='cat' href='cat.php?id=$r[id]'>- $r[title]</a>";
}

?>
试试这段代码

function menucategories() {
include ('connect.php');

$q=mysql_query("select  * from categories where sub='0' order by asc");
while ($r=mysql_fetch_array($q)){

    echo "<a class='cat' href='cat.php?id=$r[id]'>- $r[title]</a>";
    $q1=mysql_query("select  * from categories where sub='".$r[id]."' order by asc");
    while ($r1=mysql_fetch_array($q1)){
        echo "<a class='cat' href='cat.php?id=$r1[id]'>-- $r1[title]</a>";
    }

}
函数菜单类别(){
包括('connect.php');
$q=mysql_查询(“从类别中选择*,其中子类按asc排序为0”);
而($r=mysql\u fetch\u数组($q)){
回声“;
$q1=mysql_查询(“从类别中选择*,其中sub=””。$r[id]。“'order by asc”);
而($r1=mysql\u fetch\u数组($q1)){
回声“;
}
}

你的代码成功了。轻触一下。sub='“$r[id]。”部分支持sub='“$r['id'”。”像这样,它就可以工作了。非常感谢。看一下。在这里你可以对齐Category->sub Category->sub Category。。。