duannei0044
duannei0044
2017-04-19 11:03
浏览 118
已采纳

PHP if语句评估为false,继续执行真正的代码。 我错过了什么吗?

I have a problem with my php code. I am making a reservation app and so far so good. I am a beginner so my code might seem a little akward but please i can't seem to figure this one out even after trying some things.

    $sql1 = "SELECT COUNT(*) as total FROM tables WHERE status_id = 1 AND chair_count = 2 AND (section_id = 3 OR section_id = 4)";
    $result = mysqli_query($conn, $sql1);
    $tableCount = mysqli_fetch_assoc($result);
    //Availability info for users
        if($tableCount > 0){
            echo "Available tables: " . $tableCount['total']. " " . "<br><br>";
            //query for displaying available tables   
            $sql2 = "SELECT * FROM tables WHERE status_id = 1 AND chair_count = 2 AND (section_id = 3 OR section_id = 4)";
            $result = mysqli_query($conn, $sql2);
            while ($row = mysqli_fetch_assoc($result)) {
                array_push($availableTables,$row['tableid']);
                $resTable1 = $availableTables[array_rand($availableTables)];
            }

the code above is a query that determines if there are any available tables. if so another query is executes yada yada, thats working fine.

            }else{
                echo "Cant make reservation before today" . "(Inserted Date = " . $reservationDate . ") & " . "(Current Date = " . $today . ")" . "<br>";
            }

this is the last part that closes the if statement then proceeds to an else that wont appear.

What am i missing? Thanks in advance i appreciate it a lot!!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongtingxiao4697
    dongtingxiao4697 2017-04-19 11:06
    已采纳

    Looks like you are checking to see if the mysqli_fetch_assoc result is greater than zero. Try making that

    if($tableCount['total'] > 0){
    
    点赞 评论

相关推荐