Jump to content

[SOLVED] Arrays and variables help


Gazz1982

Recommended Posts

I have created a graph using the below code.

 

<?include("phpgraphlib.php");

$graph=new PHPGraphLib(400,300);

$data=array("1"=>20, "2"=>198, "3"=>70, "4"=>90);

$graph->addData($data);

$graph->setTitle("Definitions");

$graph->setGradient("red", "maroon");

$graph->setBarOutlineColor("black");

$graph->setTextColor("blue");

$graph->createGraph();

// Closing connection

mysql_close($link);

?>

 

This is called from a html page using

 

<img src="bar_graph.php" />

 

I have a database using mysql, how would i link this into the graph?

ie from $data=array("1"=>20, "2"=>198, "3"=>70, "4"=>90); to $data=array("1"=$a, "2"=$b, "3"=>$c, "4"=>$d);

 

in this case the $a/b/c and d would be called from a query

 

I tried the above $data=array... but it didn't work any ideas?

 

Gary

Link to comment
Share on other sites

I'm connecting to a mysql database and conducting a query using:

 

<?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

$result = mysql_query("SELECT count(*) AS def1 FROM answer where def=1")

 

or die(mysql_error()); 

while ($row = mysql_fetch_array ($result)) {

echo"<table><tr><td>Definition 1 count=".$row["def1"]."</td></tr>\n";

 

}

mysql_free_result ($result);

 

 

this echos the result of the query then I need $a=".$row["def1"]." followed by the graph code

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.