My first question, if a query returns a empty set, what's the best way to do an action based on that? Such as just print a message saying so? The way I have it set up right now is if an empty set is returned, nothing is displayed.
I tried something like this, if (mysql_num_rows($sql)==0) { echo "None"; }
, but that didn't seem to work. I tried placing that after the foreach
and before.
( $own = $_POST['flight'];
, flight
comes from a drop-down list)
<p align="center">List of passengers on that flight: <br>
<?php
if ($_SERVER['REQUEST_METHOD'] == POST) {
$own = $_POST['flight'];
$sql = "SELECT firstName, lastName FROM passenger, flight, manifest WHERE flight.flightnum =
manifest.flightnum AND manifest.passnum = passenger.passnum AND flight.flightnum = '".$own."'";
foreach($connection->query($sql) as $row ) {
echo $row['firstName']. " ". $row['lastName'];
echo '<br>';
}
}
?>
</p>
Next, I was confused on how to make an action triggered button. I want to display this (down below) after a button is clicked.
I tried making a button like this (which worked fine), <button onclick="myFunction()">Click me</button> <p id="demo"></p>
, but I cant figure out on how to write the script for it.
<p align="center">List of all passengers: <br>
<?php
$sqlRequest = "SELECT firstName, lastName FROM passenger ORDER BY lastName";
$result = $connection->query($sqlRequest); //save result
if($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo $row["firstName"]. " ". $row["lastName"]. "<br>";
}
}
?>
</p>
Sorry for sticking two questions into one. Seemed like a good idea instead of making two separate threads.