0

I am trying to display data from two tables from phpMyadmin database. I have a website with a form where you put what information are you looking for and then this information should be displayed from two tables in the database. I know I have to use a SQL JOIN, I have tried different ways and cannot figure this out. I will appreciate any help

Here is my php code:

    <?php
//connect to database:
$con = mysql_connect("SERVER", "LOGIN", "PASS") or die("Connection Failed");
mysql_select_db("TABLE", $con) or die ("Connection Failed");

//create a PHP variable to hold the value from HTML form
$from = $_POST['arrival'];
$to = $_POST['destination'];
$time = $_POST['time'];
$tailnumber = $_POST['tailnumber'];

$error_status = false;

// validating input
if (empty($_POST['arrival'])){
echo "Please enter the origin.";
$error_status = true;
} 
if (empty($_POST['destination'])){
echo "</br></br> Please enter the destination.";
$error_status = true;
} 
if (empty($_POST['time'])){
echo "</br></br> Please enter the date.";
$error_status = true;
} 
if (empty($_POST['tailnumber'])){
echo "</br></br> Please enter the tail number.";
$error_status = true;
} 

//create the query for selecting all the records which equal to the value from the form
if(!$error_status) {
$query = "SELECT *
FROM INBOUND_FLIGHT
INNER JOIN OUTBOUND_FLIGHT 
ON INBOUND_FLIGHT.TAIL_NUMBER = OUTBOUND_FLIGHT.TAIL_NUMBER
WHERE INBOUND_FLIGHT.ARRIVAL_TIME = '$time' AND INBOUND_FLIGHT.TAIL_NUMBER = '$tailnumber' AND INBOUND_FLIGHT.AIRCRAFT_FROM = '$from'AND OUTBOUND_FLIGHT.AIRCRAFT_TO = '$to'";

//run query
$result = mysql_query($query);
// creating a table
echo "<table border='1'>
<tr>
<th>ARRIVAL TIME</th>
<th>AIRCRAFT TYPE</th>
<th>TAIL NUMBER</th>
<th>CREW NAME</th>
<th>ORIGIN</th>
<th>DESTINATION</th>
</tr>";

//Print the record that matches the criteria of the query
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<tr>";
echo "<td>" . $row['INBOUND_FLIGHT.ARRIVAL_TIME'] . "</td>";
echo "<td>" . $row['INBOUND_FLIGHT.AIRCRAFT_TYPE' ] . "</td>";
echo "<td>" . $row['INBOUND_FLIGHT.TAIL_NUMBER'] . "</td>";
echo "<td>" . $row['INBOUND_FLIGHT.CREW_NAME'] . "</td>";
echo "<td>" . $row['INBOUND_FLIGHT.AIRCRAFT_FROM'] . "</td>";
echo "<td>" . $row['OUTBOUND_FLIGHT.AIRCRAFT_TO'] . "</td>";
}}
//close the connection
mysql_close($con);
echo "</table>";
?>
4

2 に答える 2

1

私はそれを機能させました。

使用しました

SELECT *
FROM INBOUND_FLIGHT, OUTBOUND_FLIGHT
...

その後、エコー表示を変更しました

echo "<td>" . $row['ARRIVAL_TIME'] . "</td>";
...
...
于 2012-11-16T19:24:23.517 に答える
0

以下のクエリ セクションの後にスペースを入れ'$from'ます。

    AND INBOUND_FLIGHT.AIRCRAFT_FROM = '$from'AND

なので

    AND INBOUND_FLIGHT.AIRCRAFT_FROM = '$from' AND
于 2012-11-16T17:25:40.053 に答える