in the following code I have 2 javascript vars that I need to pass to a google charts javascript function . Now of these two vars , one $ValueA is set to be data retrieved from a SQL query , the second $ValueD is just a var that is always = to 20 that I put for testing purposes . Now what I need to do is tell the Javacript to yield for how many seconds it takes for the query to complete ( I know the command to do this in unity is yield Wait For Seconds, but it doesn't look like you can do that in normal Javascript . For testing I print out the $ValueA var , and it prints successfully, but wont insert it self in the chart .
<html>
<?php
// Configuration
$hostname = host;
$username = 'user';
$password = 'pass';
$database = 'dbname';
$score = 'A' ;
$secretKey = "Key"; // Change this value to match the value stored in the client javascript below
$ValueD = 20 ; // this works
try {
$dbh = new PDO('mysql:host='. $hostname .';dbname='. $database, $username, $password);
echo "Connected to database"; // check for connection
//$dbh->exec("UPDATE Quiz1 SET $score = 1 WHERE Question = 1"); // THIS DOES NOT
//$dbh->exec("UPDATE Quiz1 SET B = 1 WHERE Question = 1"); // THIS WORKS
function getFruit($conn) {
$sql = 'SELECT A, B, C, D FROM Quiz1 WHERE QUESTION = 1';
foreach ($conn->query($sql) as $row) {
print $row['B'] . "\t";
print $row['A'] . "\t";
// print $row['B] . "\n";
$ValueA = $row['A'];// with this I can see the value , but it wont show up in the chart
echo $ValueA ;
}
}
getFruit($dbh);
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
/// how do I yield here until we have a value to $ValueA ????
var stack = '<?php echo $ValueD; ?>';
var stackn = parseFloat(stack);
var stacked = '<?php echo $ValueA; ?>';
var stackedn = parseFloat(stacked);
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
['Mushrooms', stackedn],
['Onions', stackn],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]
]);
// Set chart options
var options = {'title': 'stack',
'width':400,
'height':300};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<!--Div that will hold the pie chart-->
<div id="chart_div"></div>
</body>
</html>