Jump to content

Code to Pull # of Pilots in Hub


StartVM

Recommended Posts

You can do #2 by:

public static function FlightsByPilotByHub($pilotid, $icao) {
$query = "SELECT COUNT(id) as flights FROM phpvms_pireps WHERE depicao = '$icao' OR arricao = '$icao' AND pilotid = '$pilotid' AND accepted = '1'";
$result = DB::get_row($query);
return $result->flights;
}

Not tested.

Link to comment
Share on other sites

You can do #2 by:

public static function FlightsByPilotByHub($pilotid, $icao) {
$query = "SELECT COUNT(id) as flights FROM phpvms_pireps WHERE depicao = '$icao' OR arricao = '$icao' AND pilotid = '$pilotid' AND accepted = '1'";
$result = DB::get_row($query);
return $result->flights;
}

Not tested.

That would get the flights by a specific pilot

To get flights for all pilots at a hub it would be something like:

public static function CountFlightsForPilotsOfHub($icao) { //Number of flights just for pilots at this hub
$query = "SELECT COUNT(pirepid) as count FROM ".TABLE_PREFIX."pireps WHERE (arricao = '".$icao."' OR depicao = '".$icao."') AND pilotid IN(SELECT pilotid FROM ".TABLE_PREFIX."pilots WHERE hub = '".$icao."')";
$results = DB::get_row($query);
return $results->count;
}

You could probably make it more efficient using a JOIN instead but I don't have time to work it out right now

Link to comment
Share on other sites

That would get the flights by a specific pilot

To get flights for all pilots at a hub it would be something like:

public static function CountFlightsForPilotsOfHub($icao) { //Number of flights just for pilots at this hub
$query = "SELECT COUNT(pirepid) as count FROM ".TABLE_PREFIX."pireps WHERE (arricao = '".$icao."' OR depicao = '".$icao."') AND pilotid IN(SELECT pilotid FROM ".TABLE_PREFIX."pilots WHERE hub = '".$icao."')";
$results = DB::get_row($query);
return $results->count;
}

You could probably make it more efficient using a JOIN instead but I don't have time to work it out right now

Isn't that what he wants? Per pilot from the hub?

Link to comment
Share on other sites

Isn't that what he wants? Per pilot from the hub?

Does anyone have the code to pull a numerical value of the number of pilots in a specific hub? Also, the amount of flights done by pilots in that hub? Thanks! :)

My understanding of "flights done by pilots in that hub" would be all of them..

Either way both understandings have now been answered for.

  • Like 1
Link to comment
Share on other sites

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...