Hi All,

I am seeing that there is no way to retrieve more than 1 image from a mysql table?

I have googled it, looked into 10's of websites.. no solution.
How can i simply retrieve many pictures from a table,with the other columns if possible, please?

and i also know that there is an issue around:

header('Content-type: image/jpg') 

that it cannot be used more than once??

any suggestion is highly appreciated :)

thanks!!!
here is the code

<?php


// open connection
$con = mysql_connect("localhost","root","");// connecting to host

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

  // selecting db
  mysql_select_db("db", $con);


// the select statement
$query = mysql_query("SELECT * FROM images");

// executing and retrieving it
while ($row = mysql_fetch_assoc($query)){
 header('Content-type: image/jpg');
     echo $row['image'];
     }
     mysql_close($con);
?>

Recommended Answers

All 5 Replies

do you want to list these images as an image gallery in a page for example ?
and do you store these images as a path in the database or as actual image?

Hi.

I store the images as actual images in my db table.

My objective is :

1. display an html table with client name and id.
2. with each row, there will be an upload image button : the form where a user
can upload an image, <input type="file"....

3. then, i will store the image by doing: UPDATE ..WHERE id=....

To answer your first question: yes it is an image gallery but with additional functions.

thanks .
:)

Honestly, I did not try to save actual images as an actual images in the database , instead I store the image in separate directory on web server and store the path of these images in the database and I recommend that you do so
for example in the root of your website you can make a directory called images
and store the images in and then add a reference for the image path in the database
like "images/yourimagename.jpg"

and then retrieve this path by a query like this

$query = mysql_query("SELECT * FROM images");

// executing and retrieving it
while ($row = mysql_fetch_assoc($query)){
echo "<img src='{$row['image_path']}' width='' height='' />";
}
mysql_close($con);

i see, i will try it and let you know asap.
thanks!

thanks a lot man. it worked perfectly!!

I can now retrieve all the images and display them successfully!

now what remains is, to make a way to get the path of the image which has been uploaded (by the user) and store it in the db table automatically.

Also, I used <input type="file">... to make user upload file.

Any suggestion is warmly welcomed.

If I get the codes, I will gladly post it here.

Take care .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.