faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

22 of 39 people (56%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

I can't display display images retrieving from a database. Can somebody help me?

Nov 11th, 2007 09:21
Sam Ahu, Articles Hosting, Penton Wong,


Instead of storing the image into a database, I advise you to store 
the 
path instead. This will reduce server burden.
Including path into database:
- I assume you have table for product (or anything else)
- Make sure you have one field call "Image_Path" (or "Image_URL", etc)
For instance,
Field: Image_Path
type: varchar(80)  //change the size as you wish
- Assuming you store all the images in one folder (/Image, /image, etc)
Input the following into the Image_Path field of your database:
http://youdomain.com/Image/yourimage name.gif
or simply
/Image/yourimage name.gif
- When you want to call it out simply create an image field and 
replace the SRC with the Image_path, for instance:
//Database server connection
$db = mysql_connect($Your_Server, $Your_User_Name, $Your_Password) or 
die("Unable to connect database server currently.");
$Database = mysql_select_db($Your_Database, $db) or 
die("Unable to connect target database currently.");
//SQL		
$sql = "SELECT * FROM $Your_Table_Name";  
//Select all the field or simply the field you want. If you select 
individual field, please ensure you selected the Image_Path field
//SQl Result						
$sql_result = mysql_query ($sql, $db);
//Extract data
$query_data = mysql_fetch_array($sql_result);
$image_src = $query_data ["Image_Path"];
// Display image in anywhere of the page you like
<img src="<?php echo"$image_src"; ?>" >
Note: There's another simpler way to do the samething which doesn't 
require you to include the path into database at all. But, this is the 
way for you to display your image from database.
=========
developerfusion.co.uk/show/3933/
i hope that helps:
http://americanahost.com
http://www.qwesz.com
http://www.indianhandicraftsexporters.com