Jump to content

Getting a country flag


HighFlyerPL185

Recommended Posts

Hi,

I'm sure it was asked before, but I'd like to make it in a different form. How do I display a country flag onto a departure/arrival airport? Basically, I'm getting a list of departures from the database, and listing them one by one. Inside my foreach I have:

   foreach($deps as $departure)
   {
       $dep_airport = OperationsData::getAirportinfo($departure->depicao);
   ?>
   <tr>
           <td width="10%"><?php echo $departure->depicao; ?></td>
           <td width="10%"><img src="<?php echo Countries::getCountryImage($dep_airport->location); ?>" /></td>
           <td width="60%"><?php echo $dep_airport->name; ?></td>
           <td width="20%"><?php echo $departure->total; ?></td>
   </tr>

If you look at row 2, I'm trying to generate an image for the country that the airport is in. Example: if Dublin, display Irish flag etc. I've tried depicao too beside location but it doesn't work. Any ideas?

I think I have a vague idea of what it's doing, it's basically getting a full name of the country, but we'd like it only to be two chars for the file name, i.e GB etc.

Link to comment
Share on other sites

I am assuming you are gonna used this in the schedules so I am passing $route->depicao for the ICAO you want to search for. Change this to reflect your script if using anywhere else. ;)

<?php
$country = OperationsData::getAirportInfo($route->depicao); //or change to pass in the departure icao of the airport...
   	 $imgicao = array_search($country->country, Countries::$countries);
?>
<img src="<?php echo SITE_URL;?>/lib/images/countries/<?php echo strlower($imgicao);?>.png" alt="<?php echo $imgicao;?>"

the end result something like this for me ;)

Vcifv8g.png

  • Like 3
Link to comment
Share on other sites

Just noticed, if anyone ever encounters such an issue, I think my host uses linux, because it could not find the files, which it could find on my system. As it happens with Linux, it is case sensitive, unlike Windows, so it needs lowercase characters in our case.

Adding a strtolower(string) function fixes it all :)

<img src="<?php echo SITE_URL;?>/lib/images/countries/<?php echo strtolower($imgicao);?>.png" alt="<?php echo strtolower($imgicao);?>" />

Link to comment
Share on other sites

I added that to the code just minutes after initially posting, (as I also tried on a Linux server after the initial code dev on Windows) so I thought you included that but it seems you got my code before I updated it :) If you check, there is actually the strlower function already there :P

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

I am assuming you are gonna used this in the schedules so I am passing $route->depicao for the ICAO you want to search for. Change this to reflect your script if using anywhere else. ;)

<?php
$country = OperationsData::getAirportInfo($route->depicao); //or change to pass in the departure icao of the airport...
 $airports = OperationsData::getAllAirports();
 $imgicao = array_search($country->country, Countries::$countries);
?>
<img src="<?php echo SITE_URL;?>/lib/images/countries/<?php echo strlower($imgicao);?>.png" alt="<?php echo $imgicao;?>"

In that file edit this? Location?

Regards

Link to comment
Share on other sites

It should be placed in schedule results .tpl

<td>
<a href="<?php echo url('/schedules/details/'.$route->id);?>"><?php echo $route->code . $route->flightnum?>
(
<?php $country = OperationsData::getAirportInfo($route->depicao);
 $imgicao = array_search($country->country, Countries::$countries);
?> <img src="<?php echo SITE_URL;?>/lib/images/countries/<?php echo strlower($imgicao);?>.png" alt="<?php echo $imgicao;?>" />
<?php echo $route->depicao;?> - <?php $country = OperationsData::getAirportInfo($route->arricao);
	 $imgicao = array_search($country->country, Countries::$countries);
?> <img src="<?php echo SITE_URL;?>/lib/images/countries/<?php echo strlower($imgicao);?>.png" alt="<?php echo $imgicao;?>" />

<?php echo $route->arricao;?>)</a>
<br />

Change your current code that display the DEPICAO - ARRICAO to this. I can't be more specific. :)

Link to comment
Share on other sites

something I'm doing wrong.

With the original code on scehdules result tpl file:

<tr>

<td>

<a href="<?php echo url('/schedules/details/'.$route->id);?>"><?php echo $route->code . $route->flightnum?>

<?php echo '('.$route->depicao.' - '.$route->arricao.')'?>

</a>

<br />

my flights are shown:

original.jpg

If change the code for this:

<tr>

<td>

<a href="<?php echo url('/schedules/details/'.$route->id);?>"><?php echo $route->code . $route->flightnum?>

(

<?php $country = OperationsData::getAirportInfo($route->depicao);

$imgicao = array_search($country->country, Countries::$countries);

?> <img src="<?php echo SITE_URL;?>/lib/images/countries/<?php echo strlower($imgicao);?>.png" alt="<?php echo $imgicao;?>" />

<?php echo $route->depicao;?> - <?php $country = OperationsData::getAirportInfo($route->arricao);

$imgicao = array_search($country->country, Countries::$countries);

?> <img src="<?php echo SITE_URL;?>/lib/images/countries/<?php echo strlower($imgicao);?>.png" alt="<?php echo $imgicao;?>" />

<?php echo $route->arricao;?>)</a>

<br />

<strong>Salida: </strong><?php echo $route->deptime;?>         <strong>Destino: </strong><?php echo $route->arrtime;?><br />

<strong>Aeronave: </strong><?php echo $route->aircraft; ?> (<?php echo $route->registration;?>) <strong>Distancia: </strong><?php echo $route->distance . Config::Get('UNITS');?>

<br />

<strong>Dias Activo: </strong><?php echo Util::GetDaysCompact($route->daysofweek); ?><br />

<?php echo ($route->route=='') ? '' : '<strong>Ruta: </strong>'.$route->route.'<br />' ?>

<?php echo ($route->notes=='') ? '' : '<strong>Notes: </strong>'.html_entity_decode($route->notes).'<br />' ?>

<?php

# Note: this will only show if the above code to

# skip the schedule is commented out

if($route->bidid != 0)

{

echo 'Este vuelo ha sido asignado';

}

?>

</td>

The schedules screen change and the info show bad

infodesordenada.jpg

It can not be that hard.

I must be close.

Any ideas.

Regards

Link to comment
Share on other sites

  • 7 years later...

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