2 回答
TA贡献1780条经验 获得超1个赞
希望它会有所帮助:
<?php while($row = mysqli_fetch_assoc($result)) { ?>
<?php if($row['num_vehicles'] && $row['desc_vehicles']): ?>
<tr>
<td><?php echo $row['num_vehicles']; ?></td>
<td><?php echo $row['desc_vehicles']; ?></td>
</tr>
<?php else: ?>
<tr>
<td><?php echo "Not exist" ?></td>
<td><?php echo "Not exist" ?></td>
</tr>
<php endif; ?>
<?php } ?>
或者您可以删除“不存在”字段。
TA贡献1829条经验 获得超4个赞
感谢您的帮助,我找到了解决方案,所以我与您分享。
$vehiclenum = check_input($_POST["vehiclenum"]);
$exploded = explode(",",$vehiclenum);
$countexploded = count($exploded);
for ($i = 0; $i < $countexploded; $i++) {
if (!empty($exploded[$i])) {
$sql = "SELECT * FROM vehicles WHERE num_vehicles='$exploded[$i]'";
$result = mysqli_query($connect_db, $sql);
$num_query = mysqli_num_rows($result);
if ($num_query > 0) {
while($row = mysqli_fetch_assoc($result)) {
// sort results here
}
} else { $vehiclenumerr[] ="Vehicle Number: ".$exploded[$i]. " are NOT Exist";}
}
}
编辑:我还添加了防止 sql 注入的功能::
function check_input($data){
$data=trim($data);
$data=stripcslashes($data);
$data=htmlspecialchars($data);
return $data;
}
- 2 回答
- 0 关注
- 165 浏览
添加回答
举报