Jump to content

array help!


Gazz1982

Recommended Posts

I need help with using variables in arrays

 

this has to be completed in the next 6 hours due to a deadline

 

here is the full code, I am using it to display in a graph

 

this is the array: $data=array("1"=>$data1,"2"=>$data2);

It only seems to work using intergers ie:  $data=array("1"=>10,"2"=>67);

 

And if anyone wants to take my questionnaire go to www.noblesweb.co.uk

 

 

 

Code:

<?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/62437-array-help/
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.