1

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.

Till Helge
  • 9,253
  • 2
  • 40
  • 56
Aldaron47
  • 63
  • 1
  • 1
  • 8

2 Answers2

0

Use ajax for data retrieve an example for data fetch

$.ajax({
type: "POST",
url: "someurl.php",
dataType: "JSON",
success: function(data)
{
echo "<table> Example Demo </table>";

}

});
}
});
0
  var depID = "get id of dep" ;   
    $.ajax({
        type: "POST",
        url: "someurl.php",
        data: "DEPID="+depID,
        success: function(result)
        {
           $("yourtableID").append(result);

        }

    });

Make html at php side e.g

$html = '';
foreach($query as $value){

$html .= "<tr><td>.$value['index'].</td><td>.$value['index2'].</td></tr>";

}

echo $html;
Tariq hussain
  • 614
  • 5
  • 11