我目前正在尝试创建一个网站,在该网站中,它需要堆叠的或彼此内部的查询。
这是我正在处理的内容:
<?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/