[英]MySQL/PHP Only Returning One Result
I have seen a few topics like this so i would like to say sorry first but none of the solutions given in those topics fixed my issue. 我已经看到了几个这样的主题,所以我想首先对不起,但是这些主题中给出的解决方案都无法解决我的问题。
I am trying to make a dynamic navigation menu using php and mysql, i have multiple inputs in the database as dummy text but for some reason it only wants to show one result.. 我正在尝试使用php和mysql创建一个动态导航菜单,我在数据库中有多个输入作为伪文本,但由于某种原因,它只想显示一个结果。
Here is my code: 这是我的代码:
<?php
require_once("../includes/connect.php");
include("../includes/header.php");
include("../includes/functions.php");
?>
<div id="content">
<table id="table">
<tr>
<td id="nav">
<ul class="info">
<?php
$result = mysql_query("SELECT * FROM information LIMIT 10", $connection);
while ($row = mysql_fetch_assoc($result)){
echo "<li>{$row["menu"]}</li>";
$result = mysql_query("SELECT * FROM pages WHERE information_id ={$row["id"]} LIMIT 10", $connection);
echo "<ul class=\"pages\">";
while ($row = mysql_fetch_assoc($result)){
echo "<li>{$row["menu"]}</li>";
}
echo "</ul>";
}
?>
</ul>
</td>
<td id="main">
<h2>Main Content</h2>
</td>
</tr>
</table>
</div>
<?php
include("../includes/footer.php");
?>
</body>
</html>
Dont hate because there are tables in here lol, its not for public use and i will be converting it to grids when i get it all set up and functioning. 不要讨厌,因为这里有大声笑的桌子,它不供公众使用,当我安装并运行它们时,我会将其转换为网格。 I am not a 'pro' php programmer so be nice! 我不是“专业” PHP程序员,所以要好!
I guess the problem is here.. 我想问题就在这里。
your are pushing datas to the same variables twice.... 您将数据两次推送到相同的变量。
make first query and push to $result. 进行第一个查询并推送至$ result。 again make another query and push datas to same var $result. 再次进行另一个查询,并将数据推送到相同的var $ result。
try pushing it to seperate variable 尝试推动它以分离变量
$result1 = mysql_query("SELECT * FROM pages WHERE information_id ={$row['id']} LIMIT 10", $connection);
echo "<ul class=\"pages\">";
while ($row1 = mysql_fetch_assoc($result)){
echo "<li>{$row1["menu"]}</li>";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.