0

I have a Products_Images table which stores the images in BLOB format. I want to show all the images and product details in 'View All Products' page. To accomplish this task I have created the following program, but its not giving me the desired output. Kindly check it.

Thanks.

<?php

include 'connect.php';

$query=         "select distinct product_id, image from product_images";

$query_run=     mysql_query($query);

while ($query_fetch=    mysql_fetch_assoc($query_run))
 {




     echo '</br>';
     echo $query_fetch['image'];


 }

header("Content-type: image/jpeg");





?>

Displaying The Image

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<br />
<img src="all_images.php" alt="Image" width="50" height="50" />
<body>
</body>
</html>
2
  • you can use mysql_fetch_array() instead of mysql_fetch_assoc Commented Jul 20, 2013 at 9:30
  • done, but still no change in the result Commented Jul 20, 2013 at 9:33

2 Answers 2

1

When you are using header() function you cannot print anything prior to a header call as this directs the web server to prepare a content header

<?php

include 'connect.php';

$query=         "select distinct product_id, image from product_images";

$query_run=     mysql_query($query);

header("Content-type: image/jpeg");
while ($query_fetch=    mysql_fetch_assoc($query_run))
 {




    // echo '</br>';
     echo $query_fetch['image'];


 }

?>

Note: Please avoid using mysql* they are depreciated in php newer version keep your hands on using PDO or at least mysqli

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the reply, I have updated my code, now its not showing me the binary data,but its still not showing me the image, although its showing a blank image portion in both files.
0

why you store it in database, store your image in a folder and enter the name in the database, while calling the image in the src just write the path of the folder and php code where you mention the name.

<img src="yourfolder/<?php echo your database table field name where images names are stored?>" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.