I am trying to make two separate database queries and return the results to the form. Each result is recorded in a table.
I want to combine two queries into one and order the results by task number.
FIRST REQUEST:
//Booking
$Date= date("d/m/Y");
$driver = $_SESSION['username'];
$dbTaskRecords = "SELECT * FROM booking WHERE driver='$driver' AND Date= CAST('$Date_search' AS DATE) ORDER BY TaskNo ASC";
$dbTaskRecords_result = mysql_query($dbTaskRecords);
SECOND QUESTION:
//Return Booking
$dbTaskReturn = "SELECT * FROM returnbooking WHERE driver='$driver' AND Date= CAST('$Date_search' AS DATE) ORDER BY TaskNo ASC";
$dbTaskReturn_result = mysql_query($dbTaskReturn);
Then the results are displayed on the page through the while statement.
$i=0;
while ($row = mysql_fetch_array($dbTaskRecords_result)){
if ($i==0 ){
$time = $row["Time"];
}else{
$time = 'N/A';
}
$truckID = $row["TruckID"];
$Rego_select = mysql_query("SELECT VechicleRegistration FROM trucks WHERE TruckID = '$truckID'" )
or die("Problem reading table: " . mysql_error());
$Rego = mysql_result($Rego_select,0);
$Unregisted_select = mysql_query("SELECT Unregistered FROM trucks WHERE TruckID = '$truckID'" )
or die("Problem reading table: " . mysql_error());
$Unregisted = mysql_result($Unregisted_select,0);
$id_note = $row["BookingID"];
echo '<td><a href="taskpage.php?id='.$id_note.'"><button>'. $row['TaskNo']."</button><a/></td>";
echo "<td>". $time . "</td>";
echo "<td>". $Unregisted."</td>";
echo "<td>". $Rego."</td>";
echo "<td>".$row["PickupLocation"] . "</td>";
echo "<td>".$row["DropOffLocation"] . "</td></tr>";
$i=$i+1;
}
echo'</tr>';
I repeat the same withdrawal code for booking results.
Is it possible to combine both queries into one so that the result set from both tables can be sorted by ASC and the while statement be output.
source
share