Hello, I am working on an aviation website and on a part of my site I want it to display information regarding a pilot log book. Currently I just query all the flights for a member and use substr to get the first three digits (typically an ICAO code) then run it past a few IF's so that if there is a private registration (like N612ER, G-PCH, A6-EDG etc) I can get the right character (N, G, or A6) and then I use the character to display an image. It counts how many times each three character group is used. So lets say a member has 15 Air Canada flights (ACA), 5 Southwest flight (SWA), 3 British Airways (BAW), and 2 flights under N622ER (N62) it will display the logo for each airline, or a "private registration" image for each country after is runs pasts the IF's and turns "N62" into "N". What I would like to do is expand the capability of this so that it will count how many times the characters were used. Right now if they have three different American private registrations it displays them separately because they are actually N62 or N54, I want to group it so that all American registrations are together, British together etc. I also want to be able to support military call signs, so something like EAGLE13 (I want the word EAGLE) which my IF's that check the characters will do.
So, tl;dr if I change my query to get all the members callsigns how would I then count up each instance of an airline, private registration, or military call sign and display the top 5, highest to lowest as I do now?
Here is what the code I want to change currently looks like...
<?php
$sql = "SELECT COUNT(*) AS Nr, SUBSTR(Callsign, 1, 3) as Airline FROM {$dbprefix}Reports WHERE PilotID=$userid GROUP BY Airline ORDER BY Nr DESC LIMIT 5";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$nr = $row["Nr"];
$airline = $row["Airline"];
if ($airline[2] == '-'){//is the 3rd char a hyphen?
$icao = substr($airline,0,2);
}elseif ($airline[1] == '-'){//is the 2nd char a hyphen?
$icao = substr($airline,0,1);
}elseif (is_numeric($airline[1])){//is the 2nd char a number?
$icao = substr($airline,0,1);
}else{
$re1='((?:[a-z][a-z]+))'; //search term for a word?
if ($c=preg_match_all ("/".$re1."/is", $airline, $matches)){
$icao=$matches[1][0]; //1st occurance
}
}
$pathtofile = ($_SERVER['DOCUMENT_ROOT'] . "/cms/images/airlines/$icao.jpg");
$exists = file_exists($pathtofile);
if (file_exists($pathtofile))
echo "<tr><th class=\"profile3\"><img src=\"http://www.website.org/cms/images/airlines/$icao.jpg\" /></th><td class=\"profile2\">$nr</td></tr>";
else
echo "<tr><th class=\"profile3\">$airline</th><td class=\"profile2\">$nr</td></tr>";
}
?>