Sign in to follow this  
jay_mascis

Php, Mysql, Fusioncharts

Recommended Posts

Hi, apologies if this is really stupid and simple but have been tearing hair out for last few hours.

Am a newbie to php and fusioncharts

Seem to behaving a problem displaying graph from php retrieved from Mysql. Php code below retrieves data from mysql and plots via fusioncharts and html.

Except not really working.

Receiving a variable from another php file that sets the table for mysql table.

If manually put $x = "table", code works fine and graph is displayed but not when using a passed in variable!!

Passed in variable is ok though and echos correct data if needed.

Apologies again if seems too simple but not to me!!

any help would be appreciated

 

?php

//include("getuser.php");

$con = mysql_connect('localhost', 'root', 'admin');

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

mysql_select_db("test", $con);

 

echo $x;

$result = mysql_query("SELECT * FROM $x");

/

$xmlData = "<graph caption='Inactivity Status' xAxisName='Time' yAxisName='Watts' decimalPrecision='0' formatNumberScale='0'>";

 

while($row = mysql_fetch_array($result))

{

$chart =$row['Electricity Usage'];

$time =$row['Time'];

 

 

$xmlData .= "<set name='" . $row['Time'] . "' value='" . $row['Electricity Usage']. "' color='000000' />";

}

$xmlData .= "</graph>";

 

mysql_close($con);

echo $xmlData;

 

?>

Share this post


Link to post
Share on other sites

Hi , thanks for reply, no this doesn't seem to work either.

"SELECT * FROM $x" does actually work, when I set $x = "table" in php file.

What doesn't work though is if the variable is passed in from another file as in by $_GET or POST.

The data is passed in correctly and and can echo data retrieved from mysql but just cant chart it.

 

If i set $x in php file itself there is no problem ???

Share this post


Link to post
Share on other sites

Hi , thanks for reply, no this doesn't seem to work either.

"SELECT * FROM $x" does actually work, when I set $x = "table" in php file.

What doesn't work though is if the variable is passed in from another file as in by $_GET or POST.

The data is passed in correctly and and can echo data retrieved from mysql but just cant chart it.

 

If i set $x in php file itself there is no problem ???

 

 

Have you tried adding

 

$x = $_POST["x"];

 

before the query?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this