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

标签 php mysql mysqli

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

这是我正在处理的内容:

<?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/

相关文章:

建议表结构的 MySQL 工具或查询

php - 警告 : mysqli_connect(): MySQL server has gone away

类似于 Python Pylons 的 PHP 框架

php - str_getcsv() 不忽略引用的新行

php - 通过静态和非静态方法访问静态属性?

php - Ajax 推送系统

mysql - 在 SQLPro 中创建新的数据库连接时如何传递命令行参数?

对多对多外连接的mysql查询产生重复

php password_hash 和 password_verify 看了一遍还是不行

php - MySQL 查询仅返回 COUNT