Mysqli Where子句错误
Mysqli Where Clause Error
当我使用像 WHERE source_city = '$to_name'
这样的单个 where 子句时,它工作正常但是当添加另一个检查时它显示错误:
Warning: mysqli_fetch_array() expects parameter 1 to be 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>";
}
}
?>
多个 WHERE
语句的正确语法是:
WHERE condition1 AND condition2 AND condition3
为了完整性使用 OR
:
WHERE (condition1 AND condition2) OR (condition3 AND condition4)
当我使用像 WHERE source_city = '$to_name'
这样的单个 where 子句时,它工作正常但是当添加另一个检查时它显示错误:
Warning: mysqli_fetch_array() expects parameter 1 to be 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>";
}
}
?>
多个 WHERE
语句的正确语法是:
WHERE condition1 AND condition2 AND condition3
为了完整性使用 OR
:
WHERE (condition1 AND condition2) OR (condition3 AND condition4)