Forum Moderators: coopster

Message Too Old, No Replies

Displaying pictures

Displaying several pictures stored in a DB with one query

         

g000ze

11:48 pm on Jan 14, 2006 (gmt 0)



Dear all

I am working on an applicaion that shows several pictures on a webpage. These pictures are safed in a MySQL DB as BLOB. I noticed, that the web server suffers in its performance by printing the pictures. Let's say there are 20 pictures to show, there also are 20 queries to do. This is the way I am doing it up to now:

index.php


<?php
foreach ($icons as $value) {
echo '<img src="./show_icon.php?icon_id=' . $value . '">';
}
?>

show_icon.php


<?php
$query = "SELECT icon FROM pictures WHERE id='$_GET['icon_id'] ";
$result = @mysql_query ($query) or die (mysql_error());
$icon = @mysql_result ($result, 0, "icon");
header("Content-type: image/png");
echo $icon;
?>

Actually this works quite well, but the performance is an issue. Is there a more simple or more elegant way than the code above? Is there actually a solution to do it with one query instead of 20 queries? There is a specific reason why I want the pictures to be in the DB rather than on the filesystem.

Thanks for your help
Stefan

phparion

5:10 am on Jan 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



well i think u r doing it with one query only by sending 20 variables to it

anyway, modify your table in DB create a range, like u have pics of Jennifer Lopez then add a coloumn in your table may be called GENRE and then place a value Jennifer in it, so for all images of j'lop u have Jennifer in GENRE col. then on action page use query like

SELECT * from table where GENRE='$_GET[sendGenreValue];

superpower

6:11 am on Jan 16, 2006 (gmt 0)

10+ Year Member



Why are you saving pictures in the db?

That doesn't make any sense to me. What most people do is save the username/gallery_id/filename.jpg in mysql (or something like that) and it points to the image.

I can't imagine any reason to save the actual image in the db.