gpt4 book ai didi

php - 尝试运行多个 mysqli 查询时出错

转载 作者:行者123 更新时间:2023-11-29 22:23:14 25 4
gpt4 key购买 nike

我目前正在尝试创建一个网站,在该网站中,它需要堆叠的或彼此内部的查询。

这是我正在处理的内容:

<?php
if($getSections = $con->query("SELECT * FROM sections")) {
if($getSections->num_rows > 0) {
while($section = $getSections->fetch_assoc()) {
$sectionID = $section['sectionID'];
echo '<br>' .$section['sectionID']. ' ' .$section['sectionName'];
if($getItems = $con->query("SELECT * FROM items WHERE sectionID=$sectionID")) {
if($getItems->num_rows > 0) {
while($item = $getItems->fetch_assoc()) {
echo '<br>' .$item['itemID']. ' ' .$item['itemName'] ' ' .$item['sectionID'];
};
} else {
echo '<p class="alert">No Items</p>';
};
};
$getItems->close();
};
} else {
echo '<p class="alert">No Sections</p>';
};
};
$getSections->close();
?>

当我运行这个时,我收到一个错误:

500 - Internal server error.

There is a problem with the resource you are looking for, and it cannot be displayed.

,但是当我运行时:

<?php
if($getSections = $con->query("SELECT * FROM sections")) {
if($getSections->num_rows > 0) {
while($section = $getSections->fetch_assoc()) {
$sectionID = $section['sectionID'];
echo '<br>' .$section['sectionID']. ' ' .$section['sectionName'];

};
} else {
echo '<p class="alert">No Sections</p>';
};
};
$getSections->close();
?>

我没有收到错误消息,是我做错了什么吗?或者我的网络服务器有问题吗?

最佳答案

此行中存在语法错误,其形式为缺少句点 (.):

echo '<br>' .$item['itemID']. ' ' .$item['itemName'] . ' ' .$item['sectionID'];

关于php - 尝试运行多个 mysqli 查询时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30524623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com