Multiple images on the fly

images php coding issues or problems here.

Moderators: macek, egami, gesf

mliungman
New php-forum User
New php-forum User
Posts: 3
Joined: Wed Feb 29, 2012 12:27 pm

Multiple images on the fly

Postby mliungman » Fri Mar 09, 2012 4:43 am

Hi!

I have created a ASP-based web page that queries an access database for chemical sampling data, and then uses a PHP-script to generate charts from each of the existing chemical compounds in the query. Like this:

1. ASP code with query to filter out chemical data for station x from all years
2. For each compound in the query, call a PHP-script generating a chart using
<img source="chart.php?compound=COMPOUND"/>
3. End ASP-script

Both scripts run fast and smooth, but sometimes (the first time the page is called) some of the charts are not downloaded correctly, or at least show up as red crosses. If the page is refreshed all charts show up.

Can someone explain to me where the problem is? Is the PHP too slow, or the ASP too fast, or too many compounds asked for at once. You can check the page out at http://www.lagansvattenrad.se/htm/utdata.asp. Any advice as to where the bottleneck is would be much appreciated.

Regards, Martin

mliungman
New php-forum User
New php-forum User
Posts: 3
Joined: Wed Feb 29, 2012 12:27 pm

Re: Multiple images on the fly

Postby mliungman » Mon Apr 02, 2012 12:17 pm

I just realized that if I right-click the red cross and choose "show image" it turns out just as it should. I think that the php-script is connecting too many times to the DB at the same time. I've tried to use onerror to force the images to reload, but have not been succesful. Like this:

Code: Select all

img onerror="setTimeout(function() {this.src=this.src;},4000);" src="url... and so on


Anyone got some advice?

mliungman
New php-forum User
New php-forum User
Posts: 3
Joined: Wed Feb 29, 2012 12:27 pm

Re: Multiple images on the fly

Postby mliungman » Thu Apr 05, 2012 10:28 am

It appeared that

Code: Select all

this.src=this.src
did not force a refresh. I had to use

Code: Select all

this.src=this.src? + new Date().getTime()
, so as to bypass the cached error image.

At http://www.ultramegatech.com/2008/12/reloading-images-using-javascript/ I found the code I needed.


Return to “PHP coding => Images”

Who is online

Users browsing this forum: No registered users and 1 guest