在这里,我如何称呼我的查询,我想使用简单的if ... else语句,但是我在某个地方犯了一个错误,有人可以向我解释为什么以及为什么吗?
$result = mysqli_query($con, $sql) or die(mysqli_error($con,$sql));
echo mysqli_error($con);
$number=mysqli_num_rows($result);
while ($row= mysqli_fetch_array($result)){
$brand = $row['brand'];
$model = $row['model'];
$reg_num = $row['reg_num'];
$horse_powers = $row['horse_powers'];
$color = $row['color'];
echo $number;
if($number<1){
echo "No rented cars for this period !";
}
else{
echo $brand;
}
}
请尝试以下代码:
$number = 0;
$result = mysqli_query($con, $sql);
if (!$result)
exit(mysqli_error($con));
else
$number = mysqli_num_rows($result);
if ($number==0) {
echo "No rented cars for this period !";
} else {
while ($number){
$row = mysqli_fetch_row($result);
$brand = $row['brand'];
$model = $row['model'];
$reg_num = $row['reg_num'];
$horse_powers = $row['horse_powers'];
$color = $row['color'];
echo $brand;
$number--;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句