Page 1 of 1
pre load images created with jpgraph
Posted: Mon Feb 12, 2007 10:04 pm
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
Posted: Mon Feb 12, 2007 10:20 pm
by Kieran Huggins
Sorry - I'm not clear on what you're trying to do exactly - can you provide a URL maybe?
Posted: Mon Feb 12, 2007 10:39 pm
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
Posted: Mon Feb 12, 2007 10:48 pm
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?
Posted: Wed Feb 14, 2007 12:03 am
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
Posted: Wed Feb 14, 2007 12:55 am
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..
Posted: Wed Feb 14, 2007 5:45 am
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.
Posted: Wed Feb 14, 2007 5:47 am
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.