Jump to content

Total Pilots From Country?


Thomas

Recommended Posts

  • Administrators

$params = array(
'table' => TABLE_PREFIX.'pilots',
'fields' => 'location, COUNT(*) as `total`',
'group' => 'location ORDER BY total DESC',
);

$results = DB::quick_select($params);
if(!$results)
{
return 0;
}

That should return a list with all the countries and totals, looking like this:

Array
(
[0] => stdClass Object
(
[location] => 
[total] => 1
)

[1] => stdClass Object
(
[location] => AF
[total] => 6
)

[2] => stdClass Object
(
[location] => AT
[total] => 1
)

[3] => stdClass Object
(
[location] => AU
[total] => 2
)
... etc

This will rearrange them to be accessed per-country

$country = array();
foreach($results as $row)
{
$country[$row->location] = $row->total;
}

echo "pilots in the US: {$country['US']}";

Which will output:

pilots in the US: 6

Link to comment
Share on other sites

  • 1 month later...
  • Administrators

I think the query for that will be something like:

SELECT COUNT(pilotid) as total, location FROM phpvms_pilots GROUP BY location

mysql> SELECT COUNT(pilotid) as total, location FROM phpvms_pilots GROUP BY location;
+-------+----------+
| total | location |
+-------+----------+
| 	1 | 	|
| 	7 | AF 	|
| 	1 | AT 	|
| 	2 | AU 	|
|	18 | BE 	|
| 	1 | BF 	|
| 	1 | BG 	|
| 	2 | BR 	|
| 	4 | CA 	|
| 	1 | CV 	|
| 	3 | DE 	|
| 	1 | DK 	|
| 	1 | ES 	|
| 	3 | FR 	|
| 	9 | GB 	|
| 	1 | GR 	|
| 	1 | HU 	|
| 	2 | IE 	|
| 	3 | IT 	|
| 	2 | NL 	|
| 	1 | NZ 	|
| 	2 | PL 	|
| 	3 | PT 	|
| 	1 | RO 	|
| 	1 | SE 	|
| 	1 | SG 	|
| 	7 | US 	|
| 	1 | ZA 	|
+-------+----------+
28 rows in set (0.00 sec)

You can then loop through that list:

$country_info = DB::get_results('SELECT COUNT(pilotid) as total, location FROM '.TABLE_PREFIX.'pilots GROUP BY location');
foreach($country_info as $country)
{
echo '<img src="'.Countries::getCountryImage($country->location).'" /> ('.$country->total.')<br />';
}

That should give you the basics...you'll have to table-ize it and everything.

Link to comment
Share on other sites

  • Moderators

I think its

Countries::getCountryName($country->location)

Yes that's the code in the pilot_public_profile.tpl, but its not working in the code for some reason.

This is what im trying,

<h3>Pilot Locations</h3>
<?php 
$sql = " SELECT COUNT(pilotid) as total, location FROM phpvms_pilots GROUP BY location LIMIT 0, 9999999 ";
echo '<table cellspacing="1" cellpadding="0" border="1">';
echo '<th width="100px"><div align="left">Country Flag</div></th>';
echo '<th width="100px"><div align="center">Pilots</div></th>';
$country_info = DB::get_results('SELECT COUNT(pilotid) as total, location FROM '.TABLE_PREFIX.'pilots GROUP BY location');
foreach($country_info as $country)
{
echo '<tr>';
echo '<td align= "center">';
echo '<img src="'.Countries::getCountryImage($country->location).'" /> ';
echo 'Countries::getCountryName($userinfo->location) ';
echo '</td>';
echo '<td align="center">';
echo ' ('.$country->total.')';
echo '</td>';
echo '</tr>';
}
echo '</table>';
?>

Its outputting the flag image OK but the location name is giving me, location) ?>

Any help would be appreciated,

Cheers.

Link to comment
Share on other sites

  • 2 weeks later...
  • Moderators

Sure here you go. That will be £10 :lol:

Of course only jocking :lol: :lol:

<table width="700px" border="0" cellspacing="0" cellpadding="1">
<?php
echo '<td width="250px" valign="top">'; 
echo '<table cellspacing="1" cellpadding="1" border="1">';
echo '<th width="150px"><div align="left">Country Location</div></th>';
echo '<th width="100px"><div align="center">Pilots</div></th>';
$country_info = DB::get_results('SELECT COUNT(pilotid) as total, location FROM '.TABLE_PREFIX.'pilots GROUP BY location');
foreach($country_info as $country)
{
echo '<tr>';
echo '<td align= "left">';
echo '<img src="'.Countries::getCountryImage($country->location).'" /> ';
echo Countries::getCountryName($country->location);
echo '</td>';
echo '<td align="center">';
echo ' ('.$country->total.')';
echo '</td>';
echo '</tr>';
}
echo '</table>';
?>

You may need to mess about with the style and table but the function is there.

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