0

I try to display the image from database but only show ��n�ind���g�����Y����... I don't know which part got problem. Please help me. Every help would be appreciated. Here is my code.

timetable.php

include("include/config.php");

$sql = "SELECT * FROM time_table";
$res = mysqli_query($link, $sql);

echo "<table>";
while($row = mysqli_fetch_array($res))
{
    echo "<tr>";
    echo "<td>";?> <img src="<?php echo $row["t_image"]; ?>" height="100" width="100"> <?php echo "</td>";
    echo "<td>"; echo $row["t_name"]; echo "</td>";
    echo "</tr>";
}

echo "</table>";
?>

config.php

<?php

    $link= mysqli_connect("localhost","root","","course_registration_system");

?>

My database: time_table

t_id   t_name                t_image 
1     Use Case Diagram.jpg   [BLOB - 64 KiB]
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Pierrer
  • 13
  • 1

1 Answers1

0

In HTML, <img /> tag must have the URL of the image. Reading your question, I suppose that <?php echo $row["t_image"]; ?> outputs the complete image, not only it's URL.

In that case you have two options:

  1. Build a URL that points to another script which ouputs the image
  2. Output the image in base64, so it's embedded in the HTML.

Maybe this second option is the simplest:

<?php echo "<td>";?> 
<img src="data:image/png;base64,<?php echo base64_encode($row["t_image"]); ?>" 
     height="100" 
     width="100" />

Of course, if your image is not a PNG but a JPG, change the mimetype ccordingly,

Oscar Pérez
  • 4,377
  • 1
  • 17
  • 36