0

I am newer to PHP and I have a problem changing the resultDiv contents

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>

3 Answers 3

1

Please avoid to use mysql_* function as it is deprecated in latest version. You can use mysqli or PDO.

You can display message like this :-

<?php
    $message = (mysql_num_rows($res) == 0) ? 'No Such Flight' : '';
?>

<div id="resultDiv">
 <?php echo $message;?>
</div>
Sign up to request clarification or add additional context in comments.

Comments

0

You can do it like so:

<div id="resultDiv">
<?php
   if (mysql_num_rows($res) == 0) {
       echo "No such flight";
   } else {
       echo "Flight found";
   }
?>
</div>

Comments

0

you have misspelled "resultDiv" in get element by id, also define the div before the if condition.

<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";
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.