简体   繁体   English

while循环和if语句无法正确识别数据库输入

[英]While loop and if statement not recognizing Database input correctly

Have the following php query: 有以下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";
            }
        }
    }
}

Connection to the database was successful. 与数据库的连接成功。
$row_cnt > 0 recognizing data in database. $row_cnt > 0识别数据库中的数据。
My if statement returns "NO" when 'scholarship4' is clearly NULL and 'scholarship3' clearly has data. 当'scholarship4'显然为NULL并且'scholarship3'显然有数据时,我的if语句返回“NO”。

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. 我基本上从我的另一个正常工作的页面复制了这个代码,所以我对这里发生的事情感到惊讶。

One thing I did remove was while($row = ...) since the original data input was not of the 'select' variety. 我删除的一件事是while($row = ...)因为原始数据输入不是'select'品种。 Also, please keep in mind, this is just testing the if statement initially, whereas many if statements are currently hidden from the loop. 另外,请记住,这只是最初测试if语句,而许多if语句当前在循环中是隐藏的。

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)) {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM