Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

PHP+MYSQL+Google Visualization -- Something's not adding up.

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

PHP+MYSQL+Google Visualization -- Something's not adding up.

Postby rsangole » Tue Jan 14, 2014 7:27 am

My background - MSME, with experience programming in C++, VB, Matlab etc. No experience with mysql, PHP, html or any of the web stuff. I don't need production level code, just something up and running for my arduino project.

I have a mysql db and a domain on a server. mysql db has values I populate from my sensors. I'm creating a dashboard with google visualization gauges.

I can get these two pieces of code working on their own perfectly. This was to prove to myself that my codes do run.

"readdata.php" -- Reads temp values from my db and echos them correctly.

Code: Select all
<?php
$db="DBNAME";
$link = mysqli_connect("", "admin", "pass");
mysqli_select_db($link, $db) or die("Couldn't open $db: ".mysql_error());
$result = mysqli_query($link,"SELECT temp AS temp FROM master ORDER BY id DESC LIMIT 1");
$temp=$result->fetch_object()->temp;
echo "['temp',";
echo $temp;
echo "]";
?>

Output:
['temp',60]

"gaugetrial.html": Plots a gauge using google visualization with temp=60 correctly.

Code: Select all
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type="text/javascript">
google.load('visualization', '1', {packages: ['gauge']});
</script>
<script type="text/javascript">
function drawChart() {

    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Parameter');
    data.addColumn('number', 'Value');

    data.addRows([['temp',60]]); // <---This is the line of interest

    var options = {
    width: 250,
    height: 250,
    };
    var chart = new google.visualization.Gauge(document.getElementById('gage1'));
    chart.draw(data, options);
}
google.setOnLoadCallback(drawChart);
</script>
</head>
<body>
<div id="gage1" style="width: 600px; height: 300px;"></div>
</body>
</html>


But, when I combine these two together, and replace a portion of the code (At Line #13 in gaugetrial.html) with the following, it doesn't work... no errors on the page.. just a blank page. (Showing below only the part that changes):

Code: Select all
data.addRows([
<?php
$db="DBNAME";
$link = mysqli_connect("", "admin", "pass");
mysqli_select_db($link, $db);
$result = mysqli_query($link,"SELECT temp AS temp FROM master ORDER BY id DESC LIMIT 1");
$num=mysql_numrows($result);
$temp=$result->fetch_object()->temp;
echo "['temp',", $temp, ']';
?>
]);


I just can't figure out why.

Please help! Thank you!
rsangole
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Jan 13, 2014 6:24 pm

Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.