Strider Posted August 3, 2013 Report Share Posted August 3, 2013 I am trying to get the statsdata to show a count of how many flights have been completed by my custom kacars program. But it is not working and need help, maybe someone here has the answer. Here is the code I got: /** * Get the number of flights flown with macars */ public static function AcarsCount($airline_code = '') { $key = 'acars_count'; if($airline_code != '') { $key .= '_'.$airline_code; } $acars = "mACARS"; $total = CodonCache::read($key); if($total === false) { $sql = 'SELECT COUNT(*) AS `total` FROM `'.TABLE_PREFIX.'pireps` WHERE `source`='.$acars; if($airline_code != '') { $sql .= " AND `code`='{$airline_code}' GROUP BY `code`"; } $result = DB::get_row($sql); if(!$result) { return 0; } $total = $result->total; CodonCache::write($key, $total, '15minute'); } return $total; } That is from the StatsData.class.php file. If I have done something wrong please point it out to me. <tr> <td><strong>mACARS count:</strong> </td> <td><span class="label label-info"><?php echo StatsData::AcarsCount();?></span></td> </tr> There is the code from the frontpage_main.tpl file. No error is showing, so I have not made any php error that is critical for the site to work. Quote Link to comment Share on other sites More sharing options...
Strider Posted August 3, 2013 Author Report Share Posted August 3, 2013 I tested the sql and it works. But it wont work on the site. Quote Link to comment Share on other sites More sharing options...
Strider Posted August 3, 2013 Author Report Share Posted August 3, 2013 Can I please get some help? Quote Link to comment Share on other sites More sharing options...
Administrators simpilot Posted August 3, 2013 Administrators Report Share Posted August 3, 2013 Change $sql = 'SELECT COUNT(*) AS `total`FROM `'.TABLE_PREFIX.'pireps`WHERE `source`='.$acars; to $sql = "SELECT COUNT(*) AS total FROM ".TABLE_PREFIX."pireps WHERE source = '$acars'"; and change $sql .= " AND `code`='{$airline_code}' GROUP BY `code`"; to $sql .= " AND code = '$airline_code' GROUP BY code"; That seems to work here on my test instance, there is some syntax that is making the sql query come back null, which would not show as an error necessarily. Quote Link to comment Share on other sites More sharing options...
Strider Posted August 3, 2013 Author Report Share Posted August 3, 2013 Thanks, it now works the way I want it to. 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.