greeham Posted September 14, 2015 Report Share Posted September 14, 2015 Hello, I am trying top have a stat on the front page showing all pilots that are active. The problem is that retired pilots are also classed as active, giving a misleading figure. In my thinking I need to count the pilots that have a status of not retired but am unsure what query to use? Thanks in advance, Greeham Quote Link to comment Share on other sites More sharing options...
Moderators servetas Posted September 14, 2015 Moderators Report Share Posted September 14, 2015 Which script are you using? Quote Link to comment Share on other sites More sharing options...
greeham Posted September 14, 2015 Author Report Share Posted September 14, 2015 I am just using the standard frontpage_main.tpl file with some scripting:- <?php echo StatsData::PilotCount(); ?> Obviously gives the full count and <?php echo count(PilotGroups::getUsersInGroup('2')); ?> gives me a full list of those in the 'Active' Pilot group, but the numbers are misleading. Many thanks, Greeham Quote Link to comment Share on other sites More sharing options...
Moderators servetas Posted September 14, 2015 Moderators Report Share Posted September 14, 2015 Open your core/common/StatsData.class.php file and find this: public static function PilotCount($airline_code='') { $key = 'pilot_count'; if($airline_code != '') { $key .= '_'.$airline_code; } $total = CodonCache::read($key); if($total === false) { $params = array( 'table' => TABLE_PREFIX.'pilots', 'fields' => 'COUNT(*) as `total`', ); if(!empty($airline_code)) { $params['where']['code'] = $airline_code; $params['group'] = 'code'; } $sql = DB::build_select($params); $results = DB::get_results($sql); if(!$results) { $total = 0; } else { $total = $results[0]->total; } CodonCache::write($key, $total, '15minute'); } return $total; } after this, paste the following part of code: public static function ActivePilotCount($airline_code='') { $key = 'active_pilot_count'; if($airline_code != '') { $key .= '_'.$airline_code; } $total = CodonCache::read($key); if($total === false) { $params = array( 'table' => TABLE_PREFIX.'pilots', 'fields' => 'COUNT(*) as `total`', ); if(!empty($airline_code)) { $params['where']['code'] = $airline_code; $params['group'] = 'code'; } $params['where']['retired'] = 0; $sql = DB::build_select($params); $results = DB::get_results($sql); if(!$results) { $total = 0; } else { $total = $results[0]->total; } CodonCache::write($key, $total, '15minute'); } return $total; } After that, you will be able to show the number of the current active pilots of your virtual airline using this: <?php echo StatsData::ActivePilotCount(); ?> Quote Link to comment Share on other sites More sharing options...
greeham Posted September 14, 2015 Author Report Share Posted September 14, 2015 Fantastic work, thanks for the help. Greeham 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.