我是PHP的新手,我在更改resultDiv
内容
if(mysql_num_rows($res)==0)
{
echo "<script>document.getElementById('resultDiv').innerHTML='No such flight';</script>";
// echo "<script>alert('No Such filght');</script>";
echo "No such flight";
}
else{
echo "<table border='1'><th>flight#</th><th>Dep. City</th><th>Arrival City</th><th>Dep. Date</th><th>Arrival Date</th><th>Total Seats</th>";
while($row=mysql_fetch_array($res))
echo "<tr><td>".$row['id']."</td><td>".$row['depCity']."</td><td>".$row['arrivCity']."</td><td>".$row['depDate'].
"</td><td>".$row['arrivDate']."</td><td>".$row['totalSeats']."</td></tr>";
echo "</table>";
}
</div>
<div id="resultDiv">
Result Div
</div>
答案 0 :(得分:1)
请避免使用mysql_*函数,因为它在最新版本中已弃用。您可以使用mysqli或PDO
。
您可以显示如下信息: -
<?php
$message = (mysql_num_rows($res) == 0) ? 'No Such Flight' : '';
?>
<div id="resultDiv">
<?php echo $message;?>
</div>
答案 1 :(得分:0)
你可以这样做:
<div id="resultDiv">
<?php
if (mysql_num_rows($res) == 0) {
echo "No such flight";
} else {
echo "Flight found";
}
?>
</div>
答案 2 :(得分:0)
你在id中获取拼写错误“resultDiv”,并在if条件之前定义div。
<div id="resultDiv">
Result Div
</div>
if(mysql_num_rows($res)==0)
{
echo "<script>document.getElementById('resultDiv').innerHTML='No such flight';</script>";
echo "No such flight";
}