mysql - Incremental variable names inside PHP loop -


i'm having read series of x , y values out of table plotting pchart....i know works single series i've been trying following code work several series while now. $pidresults output of search form used extract various x , y pairs table uses value foreign key.

 $pidresults = $_session['pidresults'];     $pidsize = count($pidresults);     // select plottable data sampleslave table     ($i=0; $i<$pidsize; $i++) {     $val = $pidresults[$i];     $sql="select * sampleslave masterid=$val , xaxisdata>=1 order 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 think problem in creating variable names inside while loop (not sure correct way generate increasing variable names), cant life of me figure out whats wrong. $mydata stuff pchart, passing arrays graphing script.

any appreciated.

you should use arrays. can have x's , y's , array:

$x[0], $x[1], etc.

 ($i=0; $i<=10; $i++)   {   $x[$i] = blah blah blah  //assigns next incremental value of array $x  }  

http://www.w3schools.com/php/php_arrays.asp

other ways store these (two dimensional arrays multiple series):

$x[$series][$i] //$x[0][0]  first x point in first series $y[$series][$i] //$y[0][0] first y point in first series 

for readability, have $series string, eg 'series1' so

$x['series1'][0]; 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -