-1

As of now, I really don't know how to display image and its data in a HTML table.

Here are my fields:

Name  varchar(100)
Image blob

As of now, here is my code, but I think this is not it and it has also errors.

<?php
$host = 'localhost';
$user = 'root';
$pass = '';
mysql_connect($host, $user, $pass);
mysql_select_db('test');
$sql = "SELECT * from test_mysql";
$result = mysqli_query($db,$sql);
while($arraySomething = mysqli_fetch_array($result))
{
    echo "<img src='php/imgView.php?imgId=".$arraySomething."' />";
}
?>

The only output I want is Display Image (blob) and Data (Varchar) in a HTML Table.

TY so much for future help.

veljasije
  • 6,722
  • 12
  • 48
  • 79

1 Answers1

0

You have 2 options if you insist on storing the images within a mysql table:

  1. You can use data uris int the src property of an img tag, which will contain the image data in base64 encoding. See Data URIs post on css-trcks.com for an overview of this technique. You can find an SO post with code as well here.

Pro: you can generate the full page from a single php code run, including text and data.

Con: because the technique uses base64 encoding, large pictures will really inflate the size of the data that needs to be transferred to the client. Some older browsers do not support this feature.#


  1. Create a separate php file that takes an image id as get parameter, retrieves the image from the database, sets the correct mime header, and send the image data to the client. The main php file generates the textual content of the page only, and for each image just create a reference in the img tag's src property to the other php file that send the image to the client.

Pro: requires less data to be transferred to the client, images can be downloaded by the browsers parallely.

Con: you need to separate the generation of the textual and image output.

SO question regarding this option can be found here

Community
  • 1
  • 1
Shadow
  • 33,525
  • 10
  • 51
  • 64