I know, Here is something wrong in Image Output Section. Please, Help me to correctly show the images to 3rd no. column.

<html>
<head>
</head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<body>
<?php
include ('cont.php');
$result = mysql_query("SELECT * FROM productinput") or die(mysql_error());

echo "<center>";
	echo"<table width='500' border='1' cellspacing='0' cellpadding='0'>";
echo" <tr>";
echo"	<th>Brand</th>";
echo"   <th>Model</th>";
echo"   <th>Image</th>";
echo"   <th>Description</th>";
echo"   <th>Price</th>";
echo"  </tr>";
while ($row=mysql_fetch_array($result))
{
echo "<tr>";

echo "<td>";
echo $row['brand'];
echo "</td>";	

echo "<td>";
echo $row['model'];
echo "</td>";

echo "<td>";
echo $row['image'];
echo "</td>";

echo "<td>";
echo $row['descr'];
echo "</td>";

echo "<td>";
echo $row['price'];
echo "</td>";
echo "</tr>";
}
echo "</table>";
echo "</center>";
?>
</body>
</html>

Recommended Answers

All 8 Replies

You don't have any image tags around the echo $row['image']; so it will output plain text.

I am able to input product image to the database. But, I also able to output everything from the database without image. What can i do now?

So how are you saving the images?
- Saving images to the server and storing the location in the database
or
- Storing the image as a BLOB type in the database

I storing the image as BLOB type. I am attaching full files with sql table. Just import and work with it. Thanks

do you understand what Will is saying to you? he means put $row inside an image tag, like this

echo "<img src='".$row['image']."' />";

If you are using a BLOB field to store the images (By the way, I would not do this. The filesystem is the best place to store files, not the database, but it's up to you) you will need another script to get the data and output it as an image.

Assuming your images are in jpeg format, then the following should work. This is an example, you will need to change it for your script.

1. Change the image output:
(You will need a new file, I'll call it getimage.php for this, you will also need a unique identifier in your database such as an ID column with an auto increment, I called this $row)

echo "<td>";
echo "<img src=\"getimage.php?image_id=" . $row['id'] . "\" />";
echo "</td>";

2. Then in the getimage.php file (or whatever you named it) you will need another database call to get the row using the ID in the query string, you know how to do a SELECT so I will not detail this.
To make PHP output the image as an image, you need to set the header, then you can echo the result from the db:

header('Content-type: image/jpg');
echo $row['image'];
Member Avatar for rajarajan2017

If you just store the path of the image file then you could use:

echo "<img src='".$row['image']."' />";

If you used as a blob field then follow as Will said.

header('Content-type: image/jpg');
echo $row['image'];

Thank you both,
I learned several topics from you. I really delighted with you. I am checking. I was not with my computer. I am checking now.
Thanks
sam

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.