Guest Stormchaser Posted December 24, 2010 Report Posted December 24, 2010 Hey been adding a lot of the stats from statsdata. All of them working except for TopRoutes. Any suggestions. Calling it to my frontpage with: <?php echo StatsData::TopRoutes('DAL'); ?> Function is from StatsData.class : public static function TopRoutes($airline_code='') { $key = 'top_routes'; if($airline_code != '') { $key .= '_'.$airline_code; } $top_routes = CodonCache::read($key); if($top_routes === false) { $sql = 'SELECT * FROM `'.TABLE_PREFIX.'schedules`'; if($airline_code != '') { $sql .= " WHERE `code`='{$airline_code}' GROUP BY `code`"; } $sql =' ORDER BY `timesflown` DESC LIMIT 10'; $top_routes = DB::get_results($sql); CodonCache::write($key, $top_routes, 'medium'); } return $top_routes; } Others all work i.e. <?php echo StatsData::TotalPaxCarried('DAL'); ?> Quote
Administrators Nabeel Posted December 26, 2010 Administrators Report Posted December 26, 2010 I'm not sure what you mean by "doesn't work" - are there any errors? You'll have to be more specific Quote
Administrators simpilot Posted December 27, 2010 Administrators Report Posted December 27, 2010 I found a small glitch in the sql command - update your function to this -> public static function TopRoutes($airline_code='') { $key = 'top_routes'; if($airline_code != '') { $key .= '_'.$airline_code; } $top_routes = CodonCache::read($key); if($top_routes === false) { $sql = 'SELECT * FROM `'.TABLE_PREFIX.'schedules`'; if($airline_code != '') { $sql = $sql . " WHERE `code`='{$airline_code}'"; } $sql = $sql .' ORDER BY `timesflown` DESC LIMIT 10'; $top_routes = DB::get_results($sql); CodonCache::write($key, $top_routes, 'medium'); } return $top_routes; } Also, you will not be able to echo this command out as you are trying to do. You will need to use a foreach statement to break up the array, for example -> <?php $stats = StatsData::TopRoutes(''); foreach($stats as $stat) { echo $stat->code.$stat->flightnum.' - Times Flown '.$stat->timesflown.'<br />'; } ?> Remember to clear your cache after updating this code. Quote
Guest Stormchaser Posted January 7, 2011 Report Posted January 7, 2011 My fault I wasnt calling the function right. Did <?php $run = StatsData::TopRoutes('AMF');?> <td><?php echo StatsData::TotalFlights('AMF'); ?></td> <td><?php echo $run[0]->flightnum;?></td> <td><?php echo $run[0]->depicao;?></td> <td><?php echo $run[0]->arricao;?></td> in a table works fine. I guess the timesflown got reset cause I did reset schedules in admin and it reset timesflown. Thanks for the help!! 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.