【发布时间】:2015-07-15 20:49:04
【问题描述】:
我有三张桌子
id1 title1 id2 title2 id3 title3
1 .... 1 .... 1 .....
2 ..... 2 ..... 2 ....
3 ... 3 ..... 3 ....
4 ..... 4 ....
5 .....
假设每个 title1 都有一些 title2 并且每个 title2 内部都有一些 title3。我想要上面的输出
title1
title2
title3
title3
title2
title3
title2
title3
title3
title3
------------
title1
title2
title3
title2
title3
title3
.
.
.
.
虽然我能够创建这个 (我使用 JOIN)。我正在使用三个$command = mysqli.. 和三个while loops。就像
$command = mysqli...
while($row = mysqli_fetch_array($command)){
echo ..
$command2 = mysqli...
while($row2 = mysqli_fetch_array($command2)){
echo ..
$command3 = mysqli...
while($row3 = mysqli_fetch_array($command3)){
echo ..
}
}
}
其他人评论了我的代码并说“有什么办法不使用三个 while 循环”或“你为什么要三次调用你的数据库?”
你能做到吗?
有什么方法可以让一个 mysqli_query() 获得有意图的输出?
【问题讨论】:
-
你对标题的看法是对的,而不是关于清晰性的看法
-
@hellcode 我有 3 个连接表,用于连接语句。我没有在这里展示它们,因为我认为您可以创建一个 JOIN 表。我的意思是这个问题。如何为一个 query() 创建一个 JOIN 表?
-
@hellcode 我的英语不好。我想维基百科有标题,每个标题都有其他子标题。发生了什么?
-
已经回答了
标签: php while-loop inner-join