Already you know how to upload images to mysql database using php. Otherwise, visit upload images to mysql database using php.
The php script for retrieve images from mysql database is:
where,
mysql_query() select the row which is no '1' from mysql database.
mysql_fetch_array() return the result an associated array. You want to know about mysql fetch array().
In your img src print image name with location of image. Now you''ll get output like this:
Related Post:
Retrieve images from database:
Normally you can retrieve data from mysql table using php. Then you print the result. Similarly you retrieve image name from mysql database and print image name with located folder in '<img>' tag.
Consider following mysql table.
The php script for retrieve images from mysql database is:
<?php
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('new') or die(mysql_error());
$q=mysql_query("select * from image where no=1 ") or die(mysql_error());
$res=mysql_fetch_array($q);
?>
<img src="<?php echo 'http://localhost/upload/image/'.$res['img_name'];?>">
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('new') or die(mysql_error());
$q=mysql_query("select * from image where no=1 ") or die(mysql_error());
$res=mysql_fetch_array($q);
?>
<img src="<?php echo 'http://localhost/upload/image/'.$res['img_name'];?>">
where,
mysql_query() select the row which is no '1' from mysql database.
mysql_fetch_array() return the result an associated array. You want to know about mysql fetch array().
In your img src print image name with location of image. Now you''ll get output like this:
Related Post:
At school I am using an older version of php but at home I am using php version 5.5.11 and mysql_fetch_array () is deprecated. Please can you tell me if there is an alternative function?
ReplyDeleteYou can use mysql_fetch_assoc(), mysql_fetch_row() and mysql_fetch_object()
ReplyDeleteI used mysqli_fetch_array() and it worked, I converted all my mysql functions to mysqli! Thank you
ReplyDelete