Jump to content

Pilots List Table


mark1million

Recommended Posts

  • Moderators

Nabeel, i have a pilots list currently displayed in the va stats, listed i have all the countries displaying the flag and location in a table (for anyone else this is the code)Page in action

<?php
echo '<td align="center" 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>';
?>

Now my question is how can i split this display in to four columns as the one long list looks a bit odd, hope you know what i mean :)

Thanks

Link to comment
Share on other sites

  • Administrators

Not sure if this is what you are thinking but give it a try...

<?php
$country_info = DB::get_results('SELECT COUNT(pilotid) as total, location FROM '.TABLE_PREFIX.'pilots GROUP BY LOCATION');
$country_count = DB::get_row('SELECT COUNT(DISTINCT location) AS tot FROM '.TABLE_PREFIX.'pilots');
$column = '0';
if($country_count->tot >= 2)
       {
           $column = '1';
       }
   if($column == '1')
   {
       echo '<table cellspacing="1" cellpadding="1" border="1">';
       echo '<tr><th width="150px"><div align="left">Country Location</div></th>';
       echo '<th width="100px"><div align="center">Pilots</div></th>';
       echo '<th width="150px"><div align="left">Country Location</div></th>';
       echo '<th width="100px"><div align="center">Pilots</div></th></tr>';
       foreach($country_info as $country)
       {
                if ($column % 2)
                {
                   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>';
                if (!$column % 2)
                {
                   echo '</tr>';
                }
           $column++;
       }
       if (!$column % 2)
           {
               echo '<td> </td><td> </td></tr>';
           }
       echo '</table>';
   }
   else
   {
       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>';
       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>';
   }
?>

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