Jump to content

[SOLVED] Arrays - help


Gazz1982

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.