我学习了一段时间的MySql,我认为做一个有趣的项目会很有趣,在那里你可以搜索一架飞机。问题是,我希望在PHP中选择具有给定引擎数量的平面。这对于偶数很好,但是当使用奇数时,会出错,但只会在PHP代码中出错,而不是当我在PHPMyadmin中使用它作为查询时。
代码:
$result=mysqli_query($con, "SELECT * FROM civilPlanes WHERE engines=3");
//Normally 3 would be a POST variable
if (!$result) {
die('Error: '.mysqli_error($con));
}
if (mysqli_num_rows($result) > 1) {
echo '
<tr>
<th>Manufacturer</th>
<th>Type</th>
<th>Seats (max)</th>
<th>Tumbnail</th>
<th>Engines</th>
</tr>';
while ($row=mysqli_fetch_array($result)) {
echo '
<tr>
<td>' . $row['manufacturer'] . '</td>
<td>' . $row['type'] . '</td>
<td>' . $row['maxSeats'] . '</td>
<td>' . $row['thumbnail'] . '</td>
<td>' . $row['engines'] . '</td>
</tr>';
}
}
else {
echo 'Nothing found';
}我要找的飞机排的是:
id manufacturer type seats engineType engines
21 McDonnell Douglas MD-11 410 turbofan 3每架有其他引擎的飞机都能正常工作。
哦,这个脚本是用AJAX调用的。
提前感谢
发布于 2013-11-04 21:27:15
只有当mysqli_num_rows($result)大于一个时,才返回行。这意味着只有当有两行或更多行时,它才能工作。
发布于 2013-11-04 21:27:11
if (mysqli_num_rows($result) > 1) {您不包括只有一行的结果。将其改为:
if (mysqli_num_rows($result) > 0) {https://stackoverflow.com/questions/19777422
复制相似问题