Jump to content

Display Image from MySQL


starvinmarvin14

Recommended Posts

I have a table in mysql that has the path's of images stored. The image path is stored under the column "photo". The table looks like this:

 

    1  id

    2  name

    3  age 

    4  category 

    5  photo 

    6  rating

 

I want to create a page such as view.php?id=1 where the image is displayed according to the id. It would have to call upon the path to display it. How would I do this?

Link to comment
https://forums.phpfreaks.com/topic/253099-display-image-from-mysql/
Share on other sites

An example would be:

 

<?php
$id = (int)$_GET['id'];
$sql = mysql_query("select * from my_table where id = $id limit 1");
if(mysql_num_rows($sql) > 0){
$row = mysql_fetch_assoc($sql);
echo <<<OPT
<img src="{$row['photo']}" alt="Image" />
OPT;
}else{
header("location: /error.php");
exit;
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.