Help wrapping my head around this loop within a loop
Posted: Sat Jan 24, 2009 1:09 am
Ultimately, I need the following line in my code where the array values and the Series number are dynamically generated.
The array values represent 31 fields from a single row in a database. The series1 represents the row number, 1-65 (though a new row is added daily--hence the need for it to be dynamic).
The following code perfectly echoes everything. The only way I could make it work though was by breaking it up into several chunks. The issue is that I don't need it to echo, but to show up in the code in the form of the line above.
...which echoes:
$DataSet->AddPoint(array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,),"Serie1");
$DataSet->AddPoint(array(-1,-1,-1,-1,-1,-1,-1,-1,1,1,-1,0,-1,1,1,1,1,1,-1,-1,-1,1,1,-1,-1,0,1,0,1,0,0,),"Serie2");
$DataSet->AddPoint(array(0,1,1,1,0,-1,-1,1,1,1,0,0,1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,0,0,),"Serie3");
$DataSet->AddPoint(array(-1,0,0,-1,0,-1,1,0,0,1,0,0,-1,0,0,0,0,0,1,0,1,1,0,1,0,0,0,0,1,0,0,),"Serie4");
...and so on. Thoughts?
Code: Select all
$DataSet->AddPoint(array(1,2,3,4,5,6,7),"Serie1");
The following code perfectly echoes everything. The only way I could make it work though was by breaking it up into several chunks. The issue is that I don't need it to echo, but to show up in the code in the form of the line above.
Code: Select all
<?php
//connect to DB stuff
$k = 1;
while($row = mysql_fetch_array( $result )) {
$string1 = "$"."DataSet->AddPoint(array(";
echo $string1;
for ( $i = 0; $i < 31; $i++ ) {
$data = $row[$i].",";
echo $data;
}
$string2 = "),\"Serie".$k;
echo $string2;
$string3 = "\");";
echo $string3."<br>";
$k = $k + 1;
}
}
?>
$DataSet->AddPoint(array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,),"Serie1");
$DataSet->AddPoint(array(-1,-1,-1,-1,-1,-1,-1,-1,1,1,-1,0,-1,1,1,1,1,1,-1,-1,-1,1,1,-1,-1,0,1,0,1,0,0,),"Serie2");
$DataSet->AddPoint(array(0,1,1,1,0,-1,-1,1,1,1,0,0,1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,0,0,),"Serie3");
$DataSet->AddPoint(array(-1,0,0,-1,0,-1,1,0,0,1,0,0,-1,0,0,0,0,0,1,0,1,1,0,1,0,0,0,0,1,0,0,),"Serie4");
...and so on. Thoughts?