Moderators mark1million Posted September 12, 2011 Moderators Report Posted September 12, 2011 Gents i am having a thought about listing flight hours by type, ie i have pax flights and cargo flights, i am looking at listing the hours separately and creating awards based on hours per types, is there anything out there that anyone else has done yet and how difficult would this be to code? Quote
Administrators simpilot Posted September 13, 2011 Administrators Report Posted September 13, 2011 I dont think it would be too big of a job to create this. Best way to me would be to create a new table just to hold pilot hours (always a good idea to leave native tables alone for future updates) and then update it and collect pilot hours out of the PIREPS table and group them by the flight type field that is in that table already. Could even do it without a new table and call the data every time you want it but that could hurt performance some if there is a large number of pilots in a list and you were trying to do this for each pilot on the list. Not using a new table, maybe something like this; /core/common/HoursData.class.php <?php class HoursData extends CodonModule { function hours_bytype($pilotid, $type) { $query = "SELECT SUM(flighttime) as total FROM ".TABLE_PREFIX."pireps WHERE flighttype = '$type' AND pilotid = '$pilotid'"; $hours = DB::get_row($query); return $hours->total; } } and then in your template use <?php echo HoursData::hours_bytype('pilotid', 'P'); ?> replacing pilotid with the variable holding the id and the second parameter could be any of the types out of the config file; Config::Set( 'FLIGHT_TYPES', array( 'P'=>'Passenger', 'C'=>'Cargo', 'H'=>'Charter' ) ); If you are using it on a pilot listing page where it would be called numerous times I would add the cache feature to it so it is not scanning the database everytime the page is called, it would speed it up some. 1 Quote
Moderators mark1million Posted September 13, 2011 Author Moderators Report Posted September 13, 2011 Thanks again Dave, Quote
Guest lorathon Posted September 14, 2011 Report Posted September 14, 2011 I think you should change the query to include the following. It will give you an accurate representation of total hours. SEC_TO_TIME(SUM(TIME_TO_SEC(p.flighttime_stamp))) as totaltime Using this SUM(flighttime) as total You will not get a real total time. As it does not take into consideration that the field is a time. So it will sum as if a real number. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.