ok.. I know I can find help here 🙂
I am barely out of noobhood so be gentle 🙂
I’m trying to fetch data from a db and use it to call a pie chart in GoogChart so here is my problem… some code like db connections etc. is skipped to get to the point.
First we look at the array GoogChart uses to pass the info:
$data = array(
'8' => 6,
'3' => 3,
'9' => 2,
);
Now we look at how I am trying to do it pulling the data from a db:
//connect and query here
while ($row=mysql_fetch_array($query)){
$viewid=trim($row['id']);
$total_views=trim($row['views']);
// trimmed cuz I can't sort it out
$dat = "'$viewid' => $total_views,"; //problem likely here
}
$data = array(
$dat
);
When I echo the $dat, I get this:
'8' => 6,'3' => 3,'9' => 2,
So theoretically, it should work??? But noop 🙁
There may be a totally different way of doing this but I’m stumped… didn’t take much to do it either lol.
What you’re doing is creating an array with one element: “‘8′ => 6,’3′ => 3,’9’ => 2,”.
Instead, you should be populating an array as you go:
Of course, you could also do (not certain if this could help you, but it is an option):