如何使用PHP和mysql表创建菜单和子菜单 [英] How to create the menu and and submenu using PHP and mysql table

查看:172
本文介绍了如何使用PHP和mysql表创建菜单和子菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表中有id,refid,在我的表中列出名称

我的数据如1 0 A

2 0 B

3 0 C

4 1 A1

5 1 A2

6 2 B1

7 2 B2
8 3 C3

9 3 c4

10 3 c5

11 2 C7

12 2 C8

13 11 c9

14 11 c10



我的输出应为A

--A1

- A2

B

--B1

--B2

C

--C3

--C4

--C

到此为止它工作正常但是如果我在另一个子项目中添加子项目如何检查和打印这些值请帮我提前谢谢< br $> b $ b

我尝试了什么:



i试过这个但没有得到答案请帮助我。

i have table in that id,refid,name columns in my table
my data like 1 0 A
2 0 B
3 0 C
4 1 A1
5 1 A2
6 2 B1
7 2 B2
8 3 C3
9 3 c4
10 3 c5
11 2 C7
12 2 C8
13 11 c9
14 11 c10

my output should be A
--A1
--A2
B
--B1
--B2
C
--C3
--C4
--C5
upto this it is working fine but if i add subitems inside another subitems how to check and print the values please help me thanks in advance

What I have tried:

i tried this but not getting the answer please help me.

<pre><?php

$con = new mysqli("localhost", "root", "", "test");

$topLevelItems = "SELECT id,refid,name FROM `test` WHERE refid = 0";
$res=mysqli_query($con,$topLevelItems);

foreach($res as $item) {
 echo '<a href="...">$item["name"]</a>';
 $subItems ="SELECT id, name FROM `test` WHERE refid='$item['id']'";
 $res2=mysqli_query($con,$subItems)
 foreach($res2 as $subItem) {
    echo '<a href="...">$subItem["name"]</a>';
 }
}



 ?>

推荐答案

con = new mysqli( localhost root test);

con = new mysqli("localhost", "root", "", "test");


topLevelItems = SELECT id,refid,name FROM`test` WHERE refid = 0;
topLevelItems = "SELECT id,refid,name FROM `test` WHERE refid = 0";


res = mysqli_query(
res=mysqli_query(


这篇关于如何使用PHP和mysql表创建菜单和子菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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