HighFlyerPL185 Posted February 24, 2013 Report Posted February 24, 2013 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. Quote
Moderators Parkho Posted February 24, 2013 Moderators Report Posted February 24, 2013 Try this: $dep_airport->country Hope this works. Quote
HighFlyerPL185 Posted February 24, 2013 Author Report Posted February 24, 2013 Try this: $dep_airport->country Hope this works. Nope. Does not display anything. Any other suggestions? Quote
Sava Posted February 24, 2013 Report Posted February 24, 2013 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 3 Quote
HighFlyerPL185 Posted February 24, 2013 Author Report Posted February 24, 2013 Thanks Sava, you're a star again. I discovered it actually worked before, but it was getting the full country name and applying it to find an image i.e /united_kingdom.png and not /uk.png. But your suggestion has sorted it, thanks a lot! Quote
HighFlyerPL185 Posted February 24, 2013 Author Report Posted February 24, 2013 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);?>" /> Quote
Sava Posted February 24, 2013 Report Posted February 24, 2013 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 1 Quote
imnemina Posted April 12, 2013 Report Posted April 12, 2013 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 Quote
Txmmy83 Posted April 13, 2013 Report Posted April 13, 2013 very interesting but where to place that code? did not get it to work! Quote
Moderators Parkho Posted April 13, 2013 Moderators Report Posted April 13, 2013 You can use it in your default schedule search. Quote
Sava Posted April 13, 2013 Report Posted April 13, 2013 You place it where you need the flag to show up. If you are using it somewhere else then in the schedules, you will probably need to adjust the variable passed as mentioned. Quote
Txmmy83 Posted April 13, 2013 Report Posted April 13, 2013 thanks did it slight diffrently you can view it here: http://www.flyeurope-va.org/index.php/schedules/view Quote
imnemina Posted April 13, 2013 Report Posted April 13, 2013 I do not understand where to put code. In schedule_details.tpl? or in schedules_result.tpl? i try, but not work for me. Any help more? Regards Quote
Sava Posted April 13, 2013 Report Posted April 13, 2013 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. Quote
freshJet Posted April 13, 2013 Report Posted April 13, 2013 What about doing this for airport info, i.e not using data from the schedules? I tried it using $airport->icao but got nothing... Quote
Sava Posted April 13, 2013 Report Posted April 13, 2013 Which module for airport are you using? I don't know which variables you are working with. Quote
imnemina Posted April 13, 2013 Report Posted April 13, 2013 Almost the flags icon shows broken. Quote
Sava Posted April 13, 2013 Report Posted April 13, 2013 Just copy over the code again, I've changed it a bit. Sorry for that, used my old code w/o strlower() Quote
imnemina Posted April 13, 2013 Report Posted April 13, 2013 No case. There is something wrong. Thanks Quote
freshJet Posted April 13, 2013 Report Posted April 13, 2013 Which module for airport are you using? I don't know which variables you are working with. Forgot I posted this, it was just a simple case of forgetting the strtolower() Quote
imnemina Posted April 14, 2013 Report Posted April 14, 2013 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: 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 It can not be that hard. I must be close. Any ideas. Regards Quote
imnemina Posted April 15, 2013 Report Posted April 15, 2013 Can anyone help? There are cash! :D :D Quote
freshJet Posted April 15, 2013 Report Posted April 15, 2013 It should be strtolower(), not strlower() <img src="<?php echo SITE_URL;?>/lib/images/countries/<?php echo strtolower($imgicao);?>.png" alt="<?php echo $imgicao;?>" /> Quote
imnemina Posted April 15, 2013 Report Posted April 15, 2013 It should be strtolower(), not strlower() <img src="<?php echo SITE_URL;?>/lib/images/countries/<?php echo strtolower($imgicao);?>.png" alt="<?php echo $imgicao;?>" /> 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.