While循环和if语句无法正确识别数据库输入 [英] While loop and if statement not recognizing Database input correctly

查看:96
本文介绍了While循环和if语句无法正确识别数据库输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有以下php查询:

if ($result = mysqli_query($conn, "SELECT scholarship1, scholarship2, scholarship3, scholarship4, scholarship5, scholarship6, scholarship7, scholarship8, scholarship9, scholarship10, date1, date2, date3, date4, date4, date5, date6, date7, date8, date9, date10 FROM scholarships")) {
                    $row_cnt = mysqli_num_rows($result);

            if (($row_cnt) > 0) {
                while(mysqli_fetch_assoc($result)) {

            if ((['scholarship4'] == null) AND (['scholarship3'] != null)) {
                echo "YES";
            }
            else {
                echo "NO";
            }
        }
    }
}

与数据库的连接成功.
$row_cnt > 0识别数据库中的数据.
当'scholarship4'明显为NULL并且'scholarship3'明显具有数据时,我的if语句返回"NO".

Connection to the database was successful.
$row_cnt > 0 recognizing data in database.
My if statement returns "NO" when 'scholarship4' is clearly NULL and 'scholarship3' clearly has data.

我本质上是从另一个正常运行的页面复制了此代码,因此我对这里发生的事情感到惊讶.

I essentially copied this code from another of my pages that was working properly, so I am flabbergasted as to what is going on here.

我删除的一件事是while($row = ...),因为原始数据输入不是'select'品种.另外,请记住,这只是在最初测试if语句,而当前循环中隐藏了许多if语句.

One thing I did remove was while($row = ...) since the original data input was not of the 'select' variety. Also, please keep in mind, this is just testing the if statement initially, whereas many if statements are currently hidden from the loop.

如果需要更多信息,请告诉我.感谢您提供的所有帮助.

Please let me know if more information is needed. Thanks for any and all help.

推荐答案

获取数据时,需要存储数据,然后在测试中引用此数组...

When you fetch the data, you need to store it and then reference this array in your test...

        while($row = mysqli_fetch_assoc($result)) {

            if (($row['scholarship4'] == null) AND ($row['scholarship3'] != null)) {

这篇关于While循环和if语句无法正确识别数据库输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆