Hello guys and sorry if this is a double post.
I have created a database that contains 4 values FLID
, DEPID
, ARRID
, Distance
.
I managed to use an Ajax method to display the data of one of the rows of the database:
<?php
if( isset($_POST['DEPID']) === true && empty($_POST['DEPID']) ===false){
require'../db/connect.php';
$query = mysql_query("
SELECT `Flights`.`FLID`,`Flights`.`DEPID`,`Flights`.`ARRID`,`Flights`.`Distance`
FROM `Flights`
WHERE `Flights`.`DEPID` ='".mysql_real_escape_string(trim($_POST['DEPID'])) ."'");
echo(mysql_num_rows($query)!== 0) ? mysql_result($query, 0, 'FLID') : 'Departure Airport not found ';
echo(mysql_num_rows($query)!== 0) ? mysql_result($query, 0, 'DEPID') : 'Departure Airport not found ';
echo(mysql_num_rows($query)!== 0) ? mysql_result($query, 0, 'ARRID') : 'Departure Airport not found ';
echo(mysql_num_rows($query)!== 0) ? mysql_result($query, 0, 'Distance') : 'Departure Airport not found ';
}
?>
My question is how to make this code retrieve all of the rows in the database that has the same DEPID
and how to add the results to a table.
I have created the following code in an attempt to solve my problem and I have reached this point:
<?php
if( isset($_POST['DEPID']) === true && empty($_POST['DEPID']) ===false){
require'../db/connect.php';
$query = mysql_query("SELECT * FROM Flights WHERE DEPID ='DEPID'");
$result = mysql_query($mysql_connect,$query) or die ("Error");
echo "<table><tr><th>Flight ID</th><th>Departure Airport</th><th>Arrival Airport</th><th>Distance</th></tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr><td>" . $row['FLID'] . "</td><td>" . $row['DEPID'] . "</td><td>" . $row['ARRID'] . "</td><td>" . $row['Distance'] . "</td></tr>";
}
echo "</table>";
}
Now I have the problem that the code fails with this message:
Warning: mysql_query() expects parameter 2 to be resource, boolean given in /home/ak118043/public_html/ajax/name.php on line 9 Thanks in advance.