Can anyone give me a quick explanation on how to combine 2 SQL codes together? I’m fine with HTML and PHP though I’m hopeless with SQL.
What I’m Trying to Do:
Combine:
public static function GetAllAircraft($onlyenabled=false)
{
$sql = 'SELECT *
FROM ' . TABLE_PREFIX .'aircraft';
if($onlyenabled == true)
{
$sql .= ' WHERE `enabled`=1 ';
}
$sql .= ' ORDER BY icao ASC';
return DB::get_results($sql);
}
and:
public static function AircraftUsage()
{
$sql = 'SELECT a.name AS aircraft, a.registration,
SEC_TO_TIME(SUM(TIME_TO_SEC(p.flighttime))) AS hours,
COUNT(p.distance) AS distance
FROM '.TABLE_PREFIX.'pireps p
INNER JOIN '.TABLE_PREFIX.'aircraft a ON p.aircraft = a.id
GROUP BY p.aircraft';
return DB::get_results($sql);
return $ret;
}
I am working on my Fleet Table 1.1, I need total hours and flights etc. which is located in StatsData, and I need all the other aircraft info (registration, total pax, etc.) which is located in AircraftData to be in one. So I can use data from both in one single array.
So eventually it should end up like this though, with it working
The doc isn’t finished, but the same premise for PIREPS, using the search interface. It will return all the data about a PIREP for whichever parameters you pass.
So you can search by the fields by putting them in an array:
<?php
$params = array(
'aircraftid' => [iD],
// or you can do:
'registration' => [registration],
);
// Just set the sort order to the last one
// save the old value
$old_sort_order = Config::Get('PIREPS_ORDER_BY');
Config::Set('PIREPS_ORDER_BY', 'submitdate DESC');
// Now find the PIREPS, retrieve one
$pirep = PIREPData::findPIREPS($params, 1);
$pirep = $pirep[0];
// And reset the sort order to our setting:
Config::Set('PIREPS_ORDER_BY', $old_sort_order);