Recently one of my clients asked me to make a modification to their store locator page so that when a location is selected from a drop down menu, an image of the location is displayed on the page as opposed to the generic address info that is currently displayed.
Okay, you can store images in the database as well, but that will probably eat up space much quicker than you think (depending on if you start using it for things outside of the Store Locator as well).
What you should do is store all of the images in a folder and then simply reference them in the database by name. I prefer this method as it makes a lot more sense to people that understand folder hierarchy on a server than trying to understand a database.
Firstly get together all the addresses of the images that you want to use. Then get together all the information about your database – you will need your database name, username and password. For the purposes of this you can just create a new .php page and open it once. Here is the code for that page.
$dbhost = “localhost”;
$dbname = “PUT YOUR DATABASE NAME HERE”;
$dbuser = “PUT YOUR USERNAME HERE”;
$dbpass = “PUT YOUR PASSWORD HERE”;
mysql_connect($dbhost, $dbuser, $dbpass) or die(‘>>Error connecting to Database ‘);
mysql_select_db($dbname) or die(‘>>Unable to select Database’);
mysql_query(“CREATE TABLE images(id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(30), address VARCHAR(200))”) or die(‘>>Error Creating Table ‘);
mysql_query(“INSERT INTO images(name, address)
VALUES(‘PUT THE IMAGE NAME HERE’, ‘PUT THE ADDRESS HERE’)”) or die(‘>>Unable to insert info ‘);
echo “>>Table Created “;
And when you want to retrieve the information use-
$result = mysql_query(“SELECT address FROM images WHERE name = $selected “) or die(‘>>Unable to select Table’);
$row = mysql_fetch_array($result) or die(‘>>Unable to Fetch data’);
$address = $row[‘address’];
The variable $selected needs to be set from the drop down box and needs to be the name of the image. This should work, but PM me if there are any problems.