I'm having to read a series of X and Y values out of a table for plotting with pChart....i know this works for single series but I've been trying to get the following code to work for several series for a while now. $pidresults are the output of a search form which are used to extract the various X and Y pairs from another table which uses that value as its foreign key.
$pidresults = $_SESSION['pidresults'];
$pidsize = count($pidresults);
// select plottable data from sampleSlave table
for ($i=0; $i<$pidsize; $i++) {
$val = $pidresults[$i];
$sql="SELECT * FROM sampleSlave WHERE masterID=$val AND xaxisdata>=1 ORDER BY xaxisdata";
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
while ($row = mysql_fetch_array($result)) {
$varnameX = "xData$val";
$varnameY = "yData$val";
$$varnameX[] = $row['xaxisdata'];
$$varnameY[] = $row['yaxisdata'];
}
$myData->addPoints($varnameX,"XPID$val");
$myData->addPoints($varnameY,"YPID$val");
$myData->setSerieOnAxis("YPID$val",1);
$myData->setScatterSerie("XPID$val","YPID$val",$i+1);
$myData->setScatterSerieDescription($val,"Sample$val");
}
Essentially i think my problem is in creating the variable names inside the WHILE loop (not sure correct way to generate increasing variable names), but I cant for the life of me figure out whats wrong. The $myData stuff is just for pChart, passing the arrays to the graphing script.
Any help is greatly appreciated.