pre load images created with jpgraph

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
orlandinho
Forum Newbie
Posts: 18
Joined: Mon Feb 12, 2007 9:50 pm

pre load images created with jpgraph

Post by orlandinho »

hi

i have the following problem:
i am working with jpgraph library and i use mostly pie graphs
the way i use them is calling them in IMG tags , like this
<img src='graph1.php'>
in graph1.php, i make a query to database in order to obtain results for displaying in the graphic

if my query returns no rows , i show an empty graphic with text "NO INFORMATION FOR YOUR SEARCH"

the problem is when i display 5 or 6 graphics in the same page, if any of them return information, i see 5 graphics with text
"NO INFORMATION FOR YOUR SEARCH", i don´t want this display

what i was researching is a way to load the graphics first and keep them in a php var, if it´s posible

i hope you understand my question
and if there is a fast or better way to work with this kind of graphics, i hope any advice

i´d appreciate any help
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Sorry - I'm not clear on what you're trying to do exactly - can you provide a URL maybe?
orlandinho
Forum Newbie
Posts: 18
Joined: Mon Feb 12, 2007 9:50 pm

Post by orlandinho »

i have a main page where i have to display some graphics , in this page i call the graphics in this way:

<img src='graph1.php' width='400' height='200'>

inside graph1.php i make a query to database and with the results i display a pie graph
i use jpgraph library for this
i also check if my query returns rows, if it doesn´t, i display an image with the text "NO INFORMATION.."

what i want to do is call graph1.php before displaying it in IMG tags and save it in a php variable
so i can check if it brings no information before showing graphics

:O
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

you could record the file size of the "NO INFORMATION.." graphic and test that way, not bothering to display the <img/> tag if it matches. Graph caching might be a nice feature at that point though, since you'll essentially be creating the image twice.

For that matter, why not just test for the existence of your graph data rows before adding the <img/> element?
orlandinho
Forum Newbie
Posts: 18
Joined: Mon Feb 12, 2007 9:50 pm

Post by orlandinho »

when i display the image in <img src='graph1.php'> i can´t check the size of the image before displaying it

i used the cache and it worked well, sadly i´am not allowed to use caching in the production server

the reason why i don´t check if there is no rows before displaying the graphic is because i directly call the graphic, which i prepare in graph1.php,
it brings me a graphic as a result of calling it

all my query is made in this graph1.php

a solution is to make the graphic querys before displaying, but i would be making the quey twice
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

the best way to defeat the caching is to use a unique url with each request. append a random string to the url on each request and the caching should stop..
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

It seems to me that you should actually check if there's any data to use BEFORE you try creating the graph. If there's data, show the graph. If not, do something else :) Server side, not client side.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

orlandinho wrote:the reason why i don´t check if there is no rows before displaying the graphic is because i directly call the graphic, which i prepare in graph1.php,
it brings me a graphic as a result of calling it

all my query is made in this graph1.php
Why not have the queries run in a Model somewhere else? graph1.php is the View which uses that Model. All you need to do is ask the Model (the script which runs the queries) if there's any data and if there's not, just output an empty JPEG.
Post Reply