[prog] On the fly graphs with php

Jacinta Richardson jarich at perltraining.com.au
Fri Jul 15 17:28:28 EST 2005


Conor Daly wrote:

> I'm trying to generate a line graph from a dataset returned by a database
> query in php.  I've looked at various web resources and they all seem to
> propose:
> 
> <img src="chart.php"/>
> 
> as the way to generate a chart where chart.php is a script of my own
> devising which properly scales the chart, normalises the data and draws
> everything.  Now, that would be fine if I could figure out how to call
> functions within chart.php .  For example, I want to call the function
> makeImage($height, $width, $numPoints, $xAxisLabels, $points1, $points2...)

I think you may be making this harder for yourself than you need to be.
Rather than passing the dataset from your query to chart.php why can't you pass
the parameters used to generate that dataset and get chart.php to access the
database and do the hard work all in one place?

This would mean you'd just have to write:

<img src="chart.php?param1=$param1&param2=$param2..." />

of course you'd need to make sure that $param1 etc were properly escaped for a url.

Then chart.php would pull out the dataset, call makeImage and then call
showImage and all should be well.

all the best,

    Jacinta

-- 
   ("`-''-/").___..--''"`-._          |  Jacinta Richardson         |
    `6_ 6  )   `-.  (     ).`-.__.`)  |  Perl Training Australia    |
    (_Y_.)'  ._   )  `._ `. ``-..-'   |      +61 3 9354 6001        |
  _..`--'_..-_/  /--'_.' ,'           | contact at perltraining.com.au |
 (il),-''  (li),'  ((!.-'             |   www.perltraining.com.au   |




More information about the Programming mailing list