PHP Coding - Country Flags

This is a short piece of code that was developed for the YoYo Tech Gaming Group, in a recent project. The code simply drags out the name of a country from the database and takes that variable and drags the image with that variable as a name, with the extension of jpg or gif at the end. Then echos this image to the screen.

< src="">.png" width="18px" height="12px"/ >

As you can see we are telling an Image to appear with the "img src" opening the directory that the countries flags are stored within, in this instance it is "Flags/" and then we are jumping into the php.

We open up the php command with the usual ?php then we are echoing the variable which is stored in the database in the field Country, closing the php statement and then finishing the line of code with the file extension, which here is .png

Once run through a browser this will appear as ...

< src="Flags/USA.png" width="18px" height="12px">


Amazingly, this is a rather simple piece of code, and I will admit I got stuck with it, because before hand I was using if statements and it became a very long and extensive piece of coding, which was both a waste of my time and inefficient. However after it was pointed out to me on Coding Forums.com I did feel like slapping my self in the face because it was such an obvious solution.

Anyway the finalised product can be seen at the following location. YoYo Tech Developed Coding.

PHP truly does rock this world!
Sycrid

0 comments: