I am attempting to use google charts by providing it with data from a database using PHP. Been working for a few hours on it with a collection of code here and there and got some success using the following code.
//Array
$numData[] = "['First','Second']";
//Query
$query ="SELECT * FROM numbers";
$statement = $db->query($query);
//Loop to fetch data from database
while($row = $statement->fetch(PDO::FETCH_ASSOC))
{
$firnum = $row["First"];
$secnum = $row['Second'];
$numData[] = "['".$firnum."',".$secnum."]";
//debug see what data is being retrieved
echo $firnum . '<br />';
echo $secnum . '<br />';
}
Then I'm adding this to the google charts drawchart() part of the code
// Create the data table.
echo "var data = google.visualization.arrayToDataTable([";
echo(implode(",",$numData));
echo "]);";
Everything works fine, the chart is created however with no data in it. When testing the array it appears to be blank. The desired output would be to have the first and second numbers in a google chart via this array.
I have only just started learning php so apologies for any poor code. Any help to solve the issue behind this would be fantastic.
Cheers