opsman Posted February 4, 2018 Report Share Posted February 4, 2018 Hi, I've added a custom PIREP field so my pilots can record the number of points they get following each flight however I'm not sure how to display this in the Pilot Center as part of their profiles...any ideas? I've tried the Custom Profile Field option however this doesnt appear on the PIREP so not quite what I'm looking for :-) Any help is appreciated! Quote Link to comment Share on other sites More sharing options...
Moderators servetas Posted February 5, 2018 Moderators Report Share Posted February 5, 2018 Hmmm, what you request is not that easy because it may require a few work to be done. Open the core/common/PIREPData.class.php file and find this: public static function deleteField($id) { $sql = 'DELETE FROM ' . TABLE_PREFIX . 'pirepfields WHERE fieldid=' . $id; $res = DB::query($sql); if (DB::errno() != 0) return false; return true; //TODO: delete all of the field values! //$sql = 'DELETE FROM '.TABLE_PREFIX.' } after this, add the following part of code: public static function getSumByField($pilotid, $field) { $sql = "SELECT SUM(v.value) AS total FROM ".TABLE_PREFIX."pirepvalues AS v LEFT JOIN ".TABLE_PREFIX."pireps AS p ON p.pirepid=v.pirepid WHERE v.fieldid='$field' AND p.pilotid='$pilotid' AND v.value REGEXP '^[0-9]+$'"; $total = DB::get_row($sql); if(!$total) return 0; return $total->total; } Then within the pilot's center or any other part of your website, you can use the following code to show the total points. Just ensure that the pilot really submits numbers within the points section although I added an extra check within the where statement. <?php echo PIREPData::getSumByField(SET_HERE_THE_PILOT_ID, SET_HERE_THE_FIELD_ID); ?> Do not forget to update the SET_HERE_THE_PILOT_ID and SET_HERE_THE_FIELD_ID values accordingly. I did not test it but it should work. Let me know if it does. ___________________________________________ phpVMS Modules | Web Hosting | Pilot Awards (w/Auto Awards) | Pilot Shop | Real Booking System | Forum System Quote Link to comment Share on other sites More sharing options...
opsman Posted March 2, 2018 Author Report Share Posted March 2, 2018 Hi @servetas I've added your code to the core/common/PIREPData.class.php however when I add the following line to profile_main.php, I can see the name of the field but no values within? Grade: 4 Violations: 68 Latest XP: Here is what I added in profile_main.php <li><strong>Latest XP: </strong><?php echo PIREPData::getSumByField($pilotid, $field); ?></li> Any help would be appreciated! Thanks Nick Quote Link to comment Share on other sites More sharing options...
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.