Page 1 of 1

retaining information between pages

Posted: Mon May 31, 2004 5:35 pm
by davidklonski
Hello

I am loading images from the database by using the following method:

<img src="showImage.php?id=1">

showImage.php knows how to take the id of the imge which is passed to it via $_GET, query the database, extract the appropriate image information (content type, and actual image), and display it.

I have an efficiency problem. If I have a page which has 100 images, then I basically call showImage.php 100 times, which results in 100 queries to the database.

I would like to extract all the data I need (for all the 100 images) in a single query (possible) in the page invoking showImage.php, and pass the information to the showImage.php page somehow. Or even better, place that information in a place that will be accessible to showImage.php
This way showImage will not need to query the database.

I cannot rely on session information because one of the system requirements are that the application must be clustered.

please help

Posted: Tue Jun 01, 2004 2:49 am
by Grim...
How about if you call all 100 images at the start of the page, and put the information into an array?

Posted: Tue Jun 01, 2004 3:01 am
by davidklonski
and then what should I do with the array?
How can I pass the array to the showImage.php file for processing?

Posted: Tue Jun 01, 2004 3:07 am
by feyd
sessions could be used, if they were stored in the database...

Posted: Tue Jun 01, 2004 3:17 am
by davidklonski
I cannot use session because the application is clustered.
Also, if I store session information in the database, it will mean that the showImage.php file will need to query the database for the session info, which means I don't save any database-access time

Posted: Tue Jun 01, 2004 3:40 am
by feyd
I don't really think there's anything you can do... the browser makes each call on it's own and in an arbitrary order.. you can't send the browser 1 large piece of data and it break it apart (without Java, blech)

The only thing I can come up with: don't store the images in the database.

Posted: Tue Jun 01, 2004 4:22 am
by JAM
Perhaps I didn't read this carefully enough, but...

If you in advance (somehow) know that you are to use images 1,2,3 and 54, put those in an string.

Code: Select all

$images = '1,2,3,54';
serialize() and base64_encode() the array to get a 'cryptic' string (perhaps not needed but...), that you can forward using the URI ($_GET). Upon recieving this cryptic string, base64_decode() and unserialize() it to get the original string back, then put it in the sql using IN() as part of the where-clause:

Code: Select all

Select image from table where id in($string_goes_here)
The above is untested, needs editing and tweaking, but I was just throwing yet another idea at you. Perhaps something was of use, and good luck.

Posted: Tue Jun 01, 2004 4:34 am
by feyd
that may work for getting the images in one query, but what about the transfer to the browser? being clustered, can't really cache them anywhere except the database which isn't preferred at all..

Posted: Tue Jun 01, 2004 5:43 am
by davidklonski
feyd got the proble.
I think the best soluton would be to note store the images themselves as blobs in the database.