简体   繁体   English

Mysqli Where子句错误

[英]Mysqli Where Clause Error

When i use single where clause like WHERE source_city = '$to_name' , it work fine but when add another check it show me error: 当我使用单个WHERE source_city = '$to_name'子句(如WHERE source_city = '$to_name' ,它工作正常,但是当添加另一个检查时,它向我显示错误:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result 警告:mysqli_fetch_array()期望参数1为mysqli_result

    <?php  
        if(isset($_GET["view"])){
            $to_name = $_GET["to_name"];
            $from_name = $_GET["from_name"];
            $select_user = "SELECT * from citi 
                WHERE source_city = '$to_name' AND
                dest_city = '$from_name'";
            $run_user = mysqli_query($conn,$select_user);
            if(!$run_user){
                echo "Error!";
            }
            while ($row=mysqli_fetch_array($run_user)){
            $id = $row[0];
            $source_name = $row[1];
            $dest_name = $row[2];
            echo "
                    <br><br>
                    $id<br>
                    $source_name<br>
                    $dest_name<br>";

        }
    }

    ?>

The correct syntax for muliple WHERE statements is: 多个WHERE语句的正确语法是:

WHERE condition1 AND condition2 AND condition3

Using OR for completeness: 使用OR的完整性:

WHERE (condition1 AND condition2) OR (condition3 AND condition4)

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

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