Jump to content

Recommended Posts

Posted

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;
}

And call it FleetInfo

Can anyone help me?

Thanks,

Mitch

Posted

This is my problem:

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

$sql = Aircraft Data:Getallaircraft SQL stuff

StatsData:AircraftUsage stuff

  • Administrators
Posted

You can modify the query to be:

$sql = 'SELECT  a.*, a.name AS aircraft, a.registration,

(notice the a.*), and that will give you what you want

Posted

Thanks! Now I got it working,

Next Question (sorry)

Is it possible to get the last flight flown by that aircraft's PIREP id? Then I can just use GetReportDetails($pirepid) to get some more information.

^^

What i mean is that can i get the last filed PIREP for that aircraft? Then get the PIREP id for it?

Thanks in advance,

Mitch

  • Administrators
Posted

http://docs.phpvms.net/development/searching_schedules_and_pireps

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.

You can see the query and the fields returned:

http://bugs.phpvms.net/browser/trunk/core/common/PIREPData.class.php#L44

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);

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.

Loading...
×
×
  • Create New...