PHP   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了PHP无限循环问题大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我可以使用正确的代码来工作,但是我希望能够使用对象和方法,但是这是行不通的.重复数据库中的相同条目,直到查询崩溃.我看到其他人在while语句中有查询,但是我认为我使用的方法应该只查询一次该语句,但是很可能是错误的.谢谢.

<?PHP
include '/functions/MysqL.PHP';
$MysqL = new MysqL;
$con = MysqLi_connect("host","user","password","db");
$result = MysqLi_query($con,"SELECT * FROM reportLogger WHERE Moderator='jackginger'");
while($row = MysqLi_fetch_array($MysqL->getReports('jackginger'))) {
    $time           = $row['Time'];
    $moderator      = $row['Moderator'];
    $reason         = $row['Reason'];

    // Now for each looped row

    echo "<tr><td>".$time."</td><td>".$moderator."</td><td>".$reason."</td></tr>";
}
?>

独立班

public function __construct(){
        $this->con = MysqLi_connect("localhost","root","pass","minecraft");
        // check connection
        if (MysqLi_connect_errno()) {
            echo "Failed to connect to MysqL: " . MysqLi_connect_error();
        }
    }

    public function getUUID($userName) {
        $result = MysqLi_query($this->con,"SELECT UUID FROM loginLogger WHERE Username='" . $username . "'");
        return MysqLi_fetch_array($result)[0];
    }

    public function getReports($userName) {
        $result = MysqLi_query($this->con,"SELECT * FROM reportLogger WHERE UUID='" . $this->getUUID($userName) . "'");
        return $result;
    }

解决方法:

每次调用while($row = MysqLi_fetch_array($MysqL-> getReports(‘jackginger’)))时,您都在进行新查询,因此它一次又一次地获取相同的内容.

一个解决方案可能是:

<?PHP
include '/functions/MysqL.PHP';
$MysqL = new MysqL;
$con = MysqLi_connect("host","user","password","db");
$result = MysqLi_query($con,"SELECT * FROM reportLogger WHERE Moderator='jackginger'");
$store = $MysqL->getReports('jackginger');
while($row = MysqLi_fetch_array($storE)) {
    $time           = $row['Time'];
    $moderator      = $row['Moderator'];
    $reason         = $row['Reason'];

    // Now for each looped row

    echo "<tr><td>".$time."</td><td>".$moderator."</td><td>".$reason."</td></tr>";
}
?>

大佬总结

以上是大佬教程为你收集整理的PHP无限循环问题全部内容,希望文章能够帮你解决PHP无限循环问题所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: