0

Could you answer?

I've a table in mysql database the structure is like:
table name: img_tbl (id, image, size, format, etc..)
image defined as blob datatype inside the table.

i can retrieve single image from mysql database by using the following code.

$sql = "SELECT image,size,format FROM img_tbl";
 
        // the result of the query
        $result = mysql_query($sql) or die("Invalid query: " . mysql_error());
 
        // Header for the image
        header("Content-type: image/jpeg");
        echo mysql_result($result, 0,'imageData');

But i need to display multiple images with other attributes of table from table using php.

4
Contributors
4
Replies
11
Views
6 Years
Discussion Span
Last Post by Pallavi_1
1

write two php files, one for showing all other data

file 1.php
1)fetch data from mysql with primary key
2) show all columns
3) <img src='file2.php?imgid=currid'>

file2.php //it will contain code you have written to show image in your post above, but it will use one get parameter to load specific single image.

$sql = "SELECT image,size,format FROM img_tbl where record_id='{$_GET['imgid']}'";
 
        // the result of the query
        $result = mysql_query($sql) or die("Invalid query: " . mysql_error());
 
        // Header for the image
        header("Content-type: image/jpeg");
        echo mysql_result($result, 0,'imageData');
Votes + Comments
Thank You. this code was really helpful for me and for other who has same problem.
0

dear untrived,
thank you very much for given such a usefull logic.

0

filename:display.php

<?php

    $con=@mysql_connect('localhost','root','')or die(mysql_error());

    $sdb=@mysql_select_db('interview', $con)or die(mysql_error());

    $sql = "SELECT image FROM prodlist where id='{$_GET["id"]}'";

  // the result of the query
    $result = mysql_query($sql) or die("Invalid query: " . mysql_error());

  // Header for the image
    header("Content-type: image/jpeg");
    echo mysql_result($result, 0,'image');

?>

when i need to display a image, it works perfectly. when i updated image, change image to mysql table successfully, but image not displayed. It shows "The image cannot be displayed, it contains errors". Help me.
mysql table successfully,

Edited by Dani: Formatting fixed

0

hey there i have a page where i want to display a carousel with multiple images
based on category selection plz help me

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.