marksie1988 Posted May 27, 2007 Share Posted May 27, 2007 ok i have a script that can do ip2country and i need to show the flags on it but i dont know how to call the data from the database and then add the .png image extention on the end of it anyone know? cheers Steve Quote Link to comment https://forums.phpfreaks.com/topic/53109-solved-show-images-using-mysql-data/ Share on other sites More sharing options...
MadTechie Posted May 27, 2007 Share Posted May 27, 2007 why not just use <?php header("Content-Type: image/png"); imagepng($DBimg); ?> of course $DBimg is the DB image Quote Link to comment https://forums.phpfreaks.com/topic/53109-solved-show-images-using-mysql-data/#findComment-262342 Share on other sites More sharing options...
marksie1988 Posted May 27, 2007 Author Share Posted May 27, 2007 would this work as the database doesnt know they are images the database has the country code for example united kingdom is UK and the image name is uk.png but the database doesnt have a specific image entry. Quote Link to comment https://forums.phpfreaks.com/topic/53109-solved-show-images-using-mysql-data/#findComment-262347 Share on other sites More sharing options...
MadTechie Posted May 27, 2007 Share Posted May 27, 2007 but the database doesnt have a specific image entry. what do you mean ? Quote Link to comment https://forums.phpfreaks.com/topic/53109-solved-show-images-using-mysql-data/#findComment-262352 Share on other sites More sharing options...
marksie1988 Posted May 27, 2007 Author Share Posted May 27, 2007 ok i have the following database (also included one line of data for you) CREATE TABLE `IPCountry` ( `IP_START` varchar(50) default NULL, `IP_END` varchar(50) default NULL, `IP_FROM` double default NULL, `IP_TO` double default NULL, `COUNTRY_CADE2` char(2) default NULL, `COUNTRY_NAME` varchar(50) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `IPCountry` -- INSERT INTO `IPCountry` VALUES ('2.6.190.56', '2.6.190.63', 33996344, 33996351, 'GB', 'United Kingdom'); And here is the php all is does is uses data in the database to find out what country an ip address is from what i want to be able to do is when the country is shown a small image of that countries flag is shown. but the database doesnt have the image locations in it and with over 60000 rows in the database its not possible to do so. <?php $DatabaseServer = "dbserver"; $Username = "dbuser"; $Password = "dbpass"; $DatabaseName = "dbname"; $link = mysql_connect($DatabaseServer, $Username, $Password) or die('Could not connect: ' . mysql_error()); mysql_select_db($DatabaseName) or die('Could not select database'); $IP = $_SERVER["REMOTE_ADDR"]; //Get the IP address $res = mysql_query("SELECT country_cade2,country_name FROM IPCountry WHERE IP_FROM<=inet_aton('$IP') AND IP_TO>=inet_aton('$IP')");//look up IP address $Codes = mysql_fetch_array($res); //get result $CountryCode = $Codes['country_cade2']; //two-letter country code $CountryName = $Codes['country_name']; //full country name echo "$CountryCode - $CountryName"; //print it out, just as an example mysql_close($link); //clean up ?> Quote Link to comment https://forums.phpfreaks.com/topic/53109-solved-show-images-using-mysql-data/#findComment-262359 Share on other sites More sharing options...
MadTechie Posted May 27, 2007 Share Posted May 27, 2007 ahh so echo "<img src='image/$CountryCode.png' alt='$CountryName' />"; i assume that you have an image in an image folder called GB.png etc EDIT Changed alt to $CountryName Quote Link to comment https://forums.phpfreaks.com/topic/53109-solved-show-images-using-mysql-data/#findComment-262362 Share on other sites More sharing options...
marksie1988 Posted May 27, 2007 Author Share Posted May 27, 2007 ok i tried that and it works but i had to change the image name to uppercase as the GB is shown in uppercase is it supposed to be case specific ? Quote Link to comment https://forums.phpfreaks.com/topic/53109-solved-show-images-using-mysql-data/#findComment-262365 Share on other sites More sharing options...
penguin0 Posted May 27, 2007 Share Posted May 27, 2007 yes images are case specific. GB is not going to work with gb. Quote Link to comment https://forums.phpfreaks.com/topic/53109-solved-show-images-using-mysql-data/#findComment-262368 Share on other sites More sharing options...
MadTechie Posted May 27, 2007 Share Posted May 27, 2007 Make all image names uppercase and use this $CountryCode = strtoupper($CountryCode); echo "<img src='image/$CountryCode.PNG' alt='$CountryName' />"; EDIT: images are case specific ON *nix servers not windows, the above code will sort this Quote Link to comment https://forums.phpfreaks.com/topic/53109-solved-show-images-using-mysql-data/#findComment-262369 Share on other sites More sharing options...
marksie1988 Posted May 27, 2007 Author Share Posted May 27, 2007 ok then i guess at least it works now will just need to get round to renaming all 502 images to uppercase :S not fun thanx for the help Quote Link to comment https://forums.phpfreaks.com/topic/53109-solved-show-images-using-mysql-data/#findComment-262374 Share on other sites More sharing options...
MadTechie Posted May 27, 2007 Share Posted May 27, 2007 If they are lower case use this $CountryCode = strtolower($CountryCode); echo "<img src='image/$CountryCode.png' alt='$CountryName' />"; Quote Link to comment https://forums.phpfreaks.com/topic/53109-solved-show-images-using-mysql-data/#findComment-262376 Share on other sites More sharing options...
marksie1988 Posted May 27, 2007 Author Share Posted May 27, 2007 aww well good it works now you guys are great help here and very speedy reply:) Quote Link to comment https://forums.phpfreaks.com/topic/53109-solved-show-images-using-mysql-data/#findComment-262378 Share on other sites More sharing options...
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.