t_bergman Posted July 8, 2013 Report Posted July 8, 2013 Does anyone have a code snippet to access database fields. I am trying to grab the total flights by a pilot, I can't seem to get this even after looking into the API. Thanks, Quote
Moderators Parkho Posted July 8, 2013 Moderators Report Posted July 8, 2013 Open PilotData.class.php and add the following function at the end before the last bracket closes: public function TotalFlightsByPilot() { $pilotid = Auth::$userinfo->pilotid; $sql = "SELECT * FROM phpvms_pireps WHERE pilotid = '$pilotid'"; return DB::get_results($sql); } Then if you need to access the flights use the following: <p> Total flight by pilot: <?php echo count( PilotData::TotalFlightsByPilot()) ;?></p> Let us know what happens. Quote
Strider Posted July 8, 2013 Report Posted July 8, 2013 Look at the code in the pilots_list.tpl file. It has the total flights flown there. You shouldn't need to add any more code. The code is already there. Quote
t_bergman Posted July 8, 2013 Author Report Posted July 8, 2013 Open PilotData.class.php and add the following function at the end before the last bracket closes: public function TotalFlightsByPilot() { $pilotid = Auth::$userinfo->pilotid; $sql = "SELECT * FROM phpvms_pireps WHERE pilotid = '$pilotid'"; return DB::get_results($sql); } Then if you need to access the flights use the following: <p> Total flight by pilot: <?php echo count( PilotData::TotalFlightsByPilot()) ;?></p> Let us know what happens. This is perfect, I can also modify this to access a lot more. Quote
t_bergman Posted July 9, 2013 Author Report Posted July 9, 2013 Open PilotData.class.php and add the following function at the end before the last bracket closes: public function TotalFlightsByPilot() { $pilotid = Auth::$userinfo->pilotid; $sql = "SELECT * FROM phpvms_pireps WHERE pilotid = '$pilotid'"; return DB::get_results($sql); } Then if you need to access the flights use the following: <p> Total flight by pilot: <?php echo count( PilotData::TotalFlightsByPilot()) ;?></p> Let us know what happens. This code works perfect for the total flight by pilots, I am trying to amend it to access aircraft data. I am building a module which will display data from the aircraft table. My code from the php file is public function FleetDetails($id) { if(!Auth::LoggedIn()) { $this->set('message', 'You must be logged in to access this feature!'); $this->render('core_error.tpl'); return; } $id = self::AircraftInfo($sql); $this->render('CrewResourceCenter/CRCFleetDetail.tpl'); $aircraftid = OperationsData::getAircraftInfo($id); } public static function AircraftInfo() { $sql = "SELECT * FROM phpvms_aircraft WHERE id = '$aircraftid'"; return DB::get_results($sql); } The tpl file is <a href="http://www.hphvirtual.com/site/index.php/CrewResourceCenter/Fleet">Back to Fleet</a><p style="text-align:left; font-family:Impact, Haettenschweiler, Arial Narrow Bold, sans-serif; color:black; font-size:medium; line-height: 0px;">Fleet Datails</p> <div id="CRCFleet"> <?php $id = $aircraftid; ?> <table border="1"> <tr> <th width="800px"><?php echo $aircraftid->fullname; ?></th> </tr> </table> <table border="1"> <tr> <th width="100px">Status</th> <td width="100px"></td> <th width="100px">Type</th> <td width="100px"><?php echo $aircraft->name; ?></td> <th width="100px">Registration</th> <td width="100px"><?php echo $aircraft->registration; ?></td> <th width="100px">Flight Hours</th> <td width="100px"><?php echo $aircraft->totaltime; ?></td> </tr> </table> </div> I am new to php programming and this might be a little above my head. Basically I am trying to display individual aircraft statistics when access from http://www.hphvirtual.com/site/index.php/CrewResourceCenter/FleetDetails/1, the number correlating to the id in the aircraft table. Thanks. Quote
Moderators Parkho Posted July 9, 2013 Moderators Report Posted July 9, 2013 Okay. First off do you know how to create a module in phpVMS? Secondly, in first stack of codes, where are they located right now. This is important. Third, variable "$id" where do you get the value for it? where is the rest of the code? Forth, in second stack of codes, you're missing a loop to go through the results back from data base. Fifth, You have a lot of issues with your code to resolve. Quote
t_bergman Posted July 9, 2013 Author Report Posted July 9, 2013 Okay. First off do you know how to create a module in phpVMS? Yes, I do know how to create a module with phpVMS, I'll admit that I am new to it however. Secondly, in first stack of codes, where are they located right now. This is important. What do you mean by stack of codes? The module folder has been created in both the modules and template folders. Third, variable "$id" where do you get the value for it? where is the rest of the code? $id is the variable for the id column in the aircraft table, not sure where the rest of the code is, I think I might have to create it. Forth, in second stack of codes, you're missing a loop to go through the results back from data base. The intention is only to display the information for one aircraft, is a loop needed? Fifth, You have a lot of issues with your code to resolve. I am aware. Quote
Moderators Parkho Posted July 9, 2013 Moderators Report Posted July 9, 2013 Sorry didn't mean to be rude. In order to display the results only for one aircraft, you'll need to pass the id of the aircraft to the function and the function will return only one record and that case the loop is not needed but if you have a table for all your aircraft then you'll definitely need a loop because the results will not be just one record. What I understood from your question is that you want to have a fleet page with all the info for each aircraft if I'm not wrong. Quote
t_bergman Posted July 10, 2013 Author Report Posted July 10, 2013 Sorry didn't mean to be rude. In order to display the results only for one aircraft, you'll need to pass the id of the aircraft to the function and the function will return only one record and that case the loop is not needed but if you have a table for all your aircraft then you'll definitely need a loop because the results will not be just one record. What I understood from your question is that you want to have a fleet page with all the info for each aircraft if I'm not wrong. Thats quite ok, I probably took it a bit harsher than I should have, the one downside to forums is that you only see text. I think I may have found some code to get this started. Thanks for the help. Quote
Moderators Parkho Posted July 12, 2013 Moderators Report Posted July 12, 2013 Okay. But if you needed any help let us know. To start with, use the default fleet page and change what you need. Quote
Tom Posted July 12, 2013 Report Posted July 12, 2013 Open PilotData.class.php and add the following function at the end before the last bracket closes: public function TotalFlightsByPilot() { $pilotid = Auth::$userinfo->pilotid; $sql = "SELECT * FROM phpvms_pireps WHERE pilotid = '$pilotid'"; return DB::get_results($sql); } Then if you need to access the flights use the following: <p> Total flight by pilot: <?php echo count( PilotData::TotalFlightsByPilot()) ;?></p> Let us know what happens. This is so inefficient, use this instead: public function TotalFlightsByPilot() { $pilotid = Auth::$userinfo->pilotid; $sql = "SELECT COUNT(pirepid) as count FROM ".TABLE_PREFIX."pireps WHERE pilotid = '$pilotid'"; $ret = DB::get_results($sql); return $ret->count; } <p>Total flight by pilot: <?php echo PilotData::TotalFlightsByPilot(); ?></p> 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.