Im trying to write a script to display images based on if there is an entry form a database for example if a text string has ABC an image will be displayed. I got that part correctly but now the problem is if there is no text sting that matches abc i want a blank image outputted for example if there are no text strings that contain abc there will be either no output or a blank image. Here is the code i have been working on.
<?php
//Begin Airline List
//FAA ident only eg AAH = Aloha
if (strpos($e[0],'AAH') !==false){
$cs='<img src="http://www.virtual-aviation.org/main/map/alogos/aah.png"/>';}
if (strpos($e[0],'AAL') !==false){
$cs='<img src="http://www.virtual-aviation.org/main/map/alogos/aal.png"/>';}
if (strpos($e[0],'SWA') !==false){
$cs='<img src="http://www.virtual-aviation.org/main/map/alogos/swa.png"/>';}
if (strpos($e[0],'UAL') !==false){
$cs='<img src="http://www.virtual-aviation.org/main/map/alogos/ual.png"/>';}
if (strpos($e[0],'HAL') !==false){
$cs='<img src="http://www.virtual-aviation.org/main/map/alogos/hal.png"/>';}
if (strpos($e[0],'DAL') !==false){
$cs='<img src="http://www.virtual-aviation.org/main/map/alogos/dal.png"/>';}
if (strpos($e[0],'ASA') !==false){
$cs='<img src="http://www.virtual-aviation.org/main/map/alogos/asa.png"/>';}
if (strpos($e[0],'TRS') !==false){
$cs='<img src="http://www.virtual-aviation.org/main/map/alogos/trs.png"/>';}
if (strpos($e[0],'KAP') !==false){
$cs='<img src="http://www.virtual-aviation.org/main/map/alogos/kap.png"/>';}
if (strpos($e[0],'CHQ') !==false){
$cs='<img src="http://www.virtual-aviation.org/main/map/alogos/chq.png"/>';}
// this is where i want to code for if there is no matching text strings
else (strpos($e[0],'CHQ','AAH','AAL','SWA','UAL','HAL','DAL','ASA','TRS','KAP','CHQ') ===false)
die $cs='<img src="http://www.virtual-aviation.org/main/map/alogos/blank.png"/>';
//End Airline Listing
?>
The best thing to do in these situations is to separate your logic from your data.
Just set
$searchto the$e[0]variable you have and all will work. I also usestriposfor case insensitivity, but this isn’t required if you can guarantee capital case. Note that this is a much better method than an if else situation and even a switch case situation because all you’re feeding in is an array and you don’t need to change any code structure at all to add or remove airlines. All you will ever need to touch is that array up the top – which is exactly what you want – to keep your code dynamic and short and allow data to be changed as needed.