So I was implementing a sponsorship admin website then I encountered some trouble around.I am aware that storing image into database could be such pain in the neck but this is required(having a filesystem to store images in the campus server is prohibited).
I create 3 tables:
- a info table storing text information,
- an image table storing images in BLOB fashion and
- a id_table table as a reference table keeping records of image id and info id.
$result=mysql_query("SELECT info_id,info_name,info_year,info_level,info_email,info_describe FROM info");
while($row = mysql_fetch_array($result))
{
echo "<td>" . $row['info_name'] . "</td>";
echo "<td>" . $row['info_year'] . "</td>";
echo "<td>" . $row['info_level' ] . "</td>";
echo "<td>" . $row['info_email'] . "</td>";
echo "<td>" . $row['info_describe'] . "</td>";
$result_image_id = mysql_query("SELECT id_image FROM id_table WHERE id_info = '{$row['info_id']}'");
$row_image = mysql_fetch_array($result_image_id);
$result_image = mysql_query("SELECT image_stuff FROM image WHERE image_id = '{$row_image['id_image']}'");
$row_2 = mysql_fetch_array($result_image);
$content=$row_2['image_stuff'];
echo "<td>" ;
header('Content-type: image/jpeg');
echo $content;
echo "</td>";
echo "</tr>";
}
Then in the browser, I was redirected to a blank page. If I delete that header function, I do have a table in the page but there is nothing in the image column.
Any suggestions ?
Additionally, I tried using an <img> tag in my while loop:
echo "<img src='$content' />";
The good news is, it kind of worked out but the image file did not display practically.
I had a table in my page with image column filled with image files, but it looked just like the server did not find the image though.
I guess there does not exist any problem with my insert script because when I was applying that img tag,the “cannot display” logo only appeared in the cell whose row is the one I did upload image file into database…
You cant use headers like that…
try something like that
Change the png for whatever type of image you stored. I havent looked at the code much but this should work.