Jump to content

TopRoutes() not working for me.[SOLVED]


Recommended Posts

Guest Stormchaser
Posted

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'); ?>

  • Administrators
Posted

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.

  • 2 weeks later...
Guest Stormchaser
Posted

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!!

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...