I am pretty new at PHP and MySQL queries. I am trying to build a Google chart from a MySQL database but after searching on Google for countless hours I could not find what I need. However I found an example that could be useful but I still can't make it the way I want. Here's an example of my table.
Apple | Orange | Strawberry
--------------------------
Like | Like | Like
Dislike | Like | Like
Dislike | Dislike | Like
Like | Dislike | Dislike
Like | Like | Like
I want to count how many Like and Dislike
for Apple
, Orange
and Strawberry
. In the chart I want it to display how many people like and dislike these 3 fruits.
Here's the code I've been looking at and I've yet figured out how to attack it.
$query = mysql_query('SELECT * FROM data');
$table = array();
$table['cols'] = array(
array('label' => 'cas', 'type' => 'string'),
array('label' => 'data', 'type' => 'number')
);
$rows = array();
while($r = mysql_fetch_assoc($query)) {
$temp = array();
$temp[] = array('v' => $r['cas']);
$temp[] = array('v' => (int) $r['data']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
echo $jsonTable;
Any example would help! Thank you.