Jump to content

Help with some code for the statsdata.class file


Strider

Recommended Posts

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.

Link to comment
Share on other sites

  • Administrators

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...