I want to put data from a database table in different graphs on the same page (in table layout). I'm using objects for my data so have to use session variables.
When I execute the script every graph is made from the last data. The image (created on the fly) which is showed is always the same.
Below my code
if (!session_is_registered('data')) {
session_register('data');
}
if (!session_is_registered('xmin')) {
session_register('xmin');
}
if (!session_is_registered('xmax')) {
session_register('xmax');
}
if (!session_is_registered('legend')) {
session_register('legend');
}
if (session_is_registered('resultaat')){
if (sizeof($resultaat->result_list)>0){
for ($j = 0;$j < sizeof($resultaat->meet_punten_temp);$j++){
$data=''; //leegmaken van data
$xmax=0;
$xmin=0;
$legend="";
//var_dump($j);
for ($i=0;$i<sizeof($resultaat->result_list);$i++){
$data[]=array("",strtotime($resultaat->result_list[$i][0]),$resultaat->result_list[$i][4+$j]); //("", tijdas, meetpunt)
}
$xmin=strtotime($resultaat->result_list[0][0]);
$xmax=strtotime($resultaat->result_list[sizeof($resultaat->result_list)-1][0]);
$legend=array($resultaat->meet_punten_temp[$j]);
//var_dump($legend);
var_dump($resultaat->meet_punten_temp);
echo "<tr><td colspan=5>image: ". $j ."<IMG SRC=\"image_script.php\" /></td></tr>", "\n";
}
}
}
How should I do this?
Johnny
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I had a similar need to plot multiple individual graphs on the same web page as inline images from a MySql database. In my case it was financial stock trading data, but the concept would work for anything.
You're on the right track, but you should consider what unique key is triggering the graph generation and encapsulate that into the <IMG src=...php?key={uniqueKeyValue}>. Then put all the database lookup/extraction into the script that generates the graph image.
Remember that these massive graph generations are happening simultaneously, that's why yours produces the same data for all graphs, the last value put into the session variables. Your parent program only needs to provide the unique key value(s) to the inline graph generation program that does all the heavy extraction, each in their own unique context.
I have an example from my own working production program I can share with you to serve as an example if you will kindly give me your email address.
_________
Mike P
globaltraveler5565@yahoo.com
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have my data stored in an object as a session variable. In the main program I have to construct the data, because I couldn't find a solution to provide the imagescript with the objectdata.
Is this different from what you do?
Johnny
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, it is different from what I do, because the strategy to put data into a session variable will not work well when graphing multiple plots. You need to move this logic down into the program related to the <IMG src=...> in order to keep the various plots data localized to its instantiation.
In your scenario, the way that the PHP engine runs, you will loop through the collection logic, putting the data into the session variables and spawn the plotting program. But the server will have looped through all the various collection steps before the secondary plotting programs are even sent out the user's browser, which will see the <IMG> tag and come back to the server at a much later point in time. You are collecting all the session data in primary program execution time, and the plot requests are happening in client browser time much later, certainly after you have finished accumulating (and overlaying) all the session data (which leaves only the last collection in memory by the time the <IMG> tag is executed.
You might try to accumulate the data into different session variables for each plot and pass only the identify of the session variable to the plot program as a command line variable, for example <IMG src='whatever.php?key=xyz123'> ,and then pluck out the session variable name from the command line and use that to pass in to the plot package. I found it easier to just pass the pertinent data base query key and do the extraction inside the secondary graphing program, takes less memory.
I'm at work right now. Let me know your email address and I'll send you my working example programs to study.
_________
Mike P
globaltraveler5565@yahoo.com
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hai,
I want to put data from a database table in different graphs on the same page (in table layout). I'm using objects for my data so have to use session variables.
When I execute the script every graph is made from the last data. The image (created on the fly) which is showed is always the same.
Below my code
if (!session_is_registered('data')) {
session_register('data');
}
if (!session_is_registered('xmin')) {
session_register('xmin');
}
if (!session_is_registered('xmax')) {
session_register('xmax');
}
if (!session_is_registered('legend')) {
session_register('legend');
}
if (session_is_registered('resultaat')){
if (sizeof($resultaat->result_list)>0){
for ($j = 0;$j < sizeof($resultaat->meet_punten_temp);$j++){
$data=''; //leegmaken van data
$xmax=0;
$xmin=0;
$legend="";
//var_dump($j);
for ($i=0;$i<sizeof($resultaat->result_list);$i++){
$data[]=array("",strtotime($resultaat->result_list[$i][0]),$resultaat->result_list[$i][4+$j]); //("", tijdas, meetpunt)
}
$xmin=strtotime($resultaat->result_list[0][0]);
$xmax=strtotime($resultaat->result_list[sizeof($resultaat->result_list)-1][0]);
$legend=array($resultaat->meet_punten_temp[$j]);
//var_dump($legend);
var_dump($resultaat->meet_punten_temp);
echo "<tr><td colspan=5>image: ". $j ."<IMG SRC=\"image_script.php\" /></td></tr>", "\n";
}
}
}
How should I do this?
Johnny
Hi, Johnny.
I had a similar need to plot multiple individual graphs on the same web page as inline images from a MySql database. In my case it was financial stock trading data, but the concept would work for anything.
You're on the right track, but you should consider what unique key is triggering the graph generation and encapsulate that into the <IMG src=...php?key={uniqueKeyValue}>. Then put all the database lookup/extraction into the script that generates the graph image.
Remember that these massive graph generations are happening simultaneously, that's why yours produces the same data for all graphs, the last value put into the session variables. Your parent program only needs to provide the unique key value(s) to the inline graph generation program that does all the heavy extraction, each in their own unique context.
I have an example from my own working production program I can share with you to serve as an example if you will kindly give me your email address.
_________
Mike P
globaltraveler5565@yahoo.com
thanks for the suggestion, this method worked for me.
Hi Mike,
I have my data stored in an object as a session variable. In the main program I have to construct the data, because I couldn't find a solution to provide the imagescript with the objectdata.
Is this different from what you do?
Johnny
Yes, it is different from what I do, because the strategy to put data into a session variable will not work well when graphing multiple plots. You need to move this logic down into the program related to the <IMG src=...> in order to keep the various plots data localized to its instantiation.
In your scenario, the way that the PHP engine runs, you will loop through the collection logic, putting the data into the session variables and spawn the plotting program. But the server will have looped through all the various collection steps before the secondary plotting programs are even sent out the user's browser, which will see the <IMG> tag and come back to the server at a much later point in time. You are collecting all the session data in primary program execution time, and the plot requests are happening in client browser time much later, certainly after you have finished accumulating (and overlaying) all the session data (which leaves only the last collection in memory by the time the <IMG> tag is executed.
You might try to accumulate the data into different session variables for each plot and pass only the identify of the session variable to the plot program as a command line variable, for example <IMG src='whatever.php?key=xyz123'> ,and then pluck out the session variable name from the command line and use that to pass in to the plot package. I found it easier to just pass the pertinent data base query key and do the extraction inside the secondary graphing program, takes less memory.
I'm at work right now. Let me know your email address and I'll send you my working example programs to study.
_________
Mike P
globaltraveler5565@yahoo.com
Thanks for the explanation and solution managed to spend a few hours down this hole myself.