Page 1 of 1

quering db for each image

Posted: Fri Jun 03, 2005 5:06 pm
by newmember
i have an html page with links to images.
the images are located in inaccessable from outside location so for each link on above page some php page is being called that in turn sends the image to browser according to passed image id.

Code: Select all

<img src="sendimage.php?imgid=8" />
something that bothers me is that each time php page is called, it accesses
database according to image id(which is primary key) to retrive image storage.
(so if i display ,say 20 images on page, the browser will ask 20 times for images and that will demand 20 db queries.)

do you think that these kind of db accesses are bad for the running server?

Posted: Fri Jun 03, 2005 5:59 pm
by pickle
Naw. If the query is just getting the filename for a given ID, it should be fine.

If this page starts getting accessed a lot (like 10+ times a minute),however, then the queries might start adding up and start affecting performance.

If this becomes a problem, maybe consider setting up a class or something to get the filenames for all the files the page is showing, then send those filenames to your sendimage.php file. That will cut down the queries from 20 times per page, to 1 time per page.

Posted: Fri Jun 03, 2005 6:22 pm
by John Cartwright
only call the database once, then store the filenames/path in a session var.

Posted: Fri Jun 03, 2005 6:28 pm
by Burrito
I thought about that too (actually I was thinking an array), but he's calling them from the <img> tags spread throughout the page...not sure that would work.

Posted: Fri Jun 03, 2005 6:51 pm
by newmember
ok thanks...
only call the database once, then store the filenames/path in a session var.
probably i'll do it this way...