Gazz1982 Posted July 29, 2007 Share Posted July 29, 2007 I have an array: $data=array("a"=5); in the array I want to change 5 with a value from an sql query which is stored as $data1 how can i get this to work? Quote Link to comment Share on other sites More sharing options...
dbillings Posted July 29, 2007 Share Posted July 29, 2007 Woo hoo doesn't get any easier than this:) <?php $data1=6; $data=array("a"=>$data1); echo $data[a]; ?> Quote Link to comment Share on other sites More sharing options...
Gazz1982 Posted July 29, 2007 Author Share Posted July 29, 2007 It didn't seem to work, here is the full code, I am using it to display in a graph this is the array: $data=array("1"=>$data1,"2"=>$data2); <?php // Connecting, selecting database $link = mysql_connect('127.0.0.1', 'root', '') or die('Could not connect: ' . mysql_error()); //echo 'Connected successfully'; mysql_select_db('gary') or die('Could not select database'); // Performing SQL query // Retrieve all the data from the "example" table $sql1 = "SELECT DISTANCE1, count(*) AS dist1 FROM answer GROUP BY DISTANCE1"; $result1 = mysql_query($sql1); $data1 = array(); while (list($distance1, $dist1) = mysql_fetch_row($result1)) { $data1[$distance1] = $dist1; } $sql2 = "SELECT DISTANCE2, count(*) AS dist2 FROM answer where DISTANCE2 = 1"; $result2 = mysql_query($sql2); $data2 = array(); while (list($distance2, $dist2) = mysql_fetch_row($result2)) { $data2[$distance2] = $dist2; } include("phpgraphlib.php"); $graph=new PHPGraphLib(400,300); $data=array("2"=>$data1); $graph->addData($data); //$graph->addData($data2); //$graph->addData($data2); $graph->setTitle("Distance"); $graph->setGridColor("153,204,255"); $graph->setGradient("red", "maroon"); $graph->setBarOutlineColor("black"); $graph->setTextColor("blue"); $graph->createGraph(); // Closing connection mysql_close($link); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.