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? Link to comment https://forums.phpfreaks.com/topic/62376-solved-arrays-help/ 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]; ?> Link to comment https://forums.phpfreaks.com/topic/62376-solved-arrays-help/#findComment-310441 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); ?> Link to comment https://forums.phpfreaks.com/topic/62376-solved-arrays-help/#findComment-310444 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.