Jump to content

Selecting certain records and displaying them


hellouthere

Recommended Posts

could do with some help for a script...

I have a table called 'aircraft' with fields... air_id, air_type, reg, status... air_id and reg are unique.

I have another table called 'reports' with fields like report_id, pilot_id, reg, destination_id.

Basically i need to select the most recent report for each 'aircraft' registration and display the 'destination_id' in a table.

This is the code i have for displaying the table so far...
[code]
$querya = "SELECT * FROM aircraft";
$resulta = mysql_query($querya);


$numbera = mysql_num_rows($resulta);

if ($numbera > 0) {

print "<table>";
print "<tr>";
print "<td bgcolor=#7B85DC width=90 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>Aircraft</b></font></td>";
print "<td bgcolor=#7B85DC width=90 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>Registration</b></font></td>";
print "<td bgcolor=#7B85DC width=90 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>Status</b></font></td>";
print "<td bgcolor=#7B85DC width=90 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>AF Hours</b></font></td>";
print "<td bgcolor=#7B85DC width=90 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>Location</b></font></td>";
print "</tr>";


for ($s=0; $s<$numbera; $s++) {
    $air = mysql_result($resulta,$s,"air_type");
    $reg = mysql_result($resulta,$s, "reg");
    $status = mysql_result($resulta,$s, "status");
$afid = mysql_result($resulta,$s, "air_id");

$query_afloc = "SELECT r1.registration, r1.destination_id
FROM reports AS r1
LEFT JOIN reports AS r2 ON r1.registration = r2.registration
                      AND r1.report_id < r2.report_id
WHERE r2.report_id IS NULL
ORDER BY registration";
$result_afloc = mysql_query($query_afloc);
$afloc = mysql_result($result_afloc,$s,"destination_id");

print "<tr>";
    print "<td width=90 height=12 align=left><font face=Arial size=1 color=#313398>$air</font></td>";
    print "<td width=90 height=12 align=left><font face=Arial size=1 color=#313398>$reg</font></td>";
if ($status == 'act') {
    print '<td width=90 height=12 align=left><img alt="Active" src="images/acstgr.gif"</img></td>';
}else if ($status == 'main') {
print '<td width=90 height=12 align=left><img alt="Maintenance" src="images/acstbl.gif"</img></td>';
}else if ($status == 'oos') {
print '<td width=90 height=12 align=left><img alt="Out Of Service" src="images/acstre.gif"</img></td>';
}
    print "<td width=90 height=12 align=left><font face=Arial size=1 color=#313398>$hour</font></td>";
    print "<td width=90 height=12 align=left><font face=Arial size=1 color=#313398>$afloc</font></td>";
    print "</tr>";
}
print "</table>";

}
[/code]

As you can see i have tried to do this already but without success... It seems to take a destination_id for each reg but not the right one... Any Help Is apreciated...
Link to comment
Share on other sites

That seems to work to a certain degree... when i display the table i get destination_id's displaying but not for the right aircraft... i only have a few aircraft with reports so far... the top 2 aircraft in the table have the location displayed by them regardless of what the registration is... this is really confusing me now i cant see anything wrong with any of the code!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.