For a graph I'm working on, I'm trying to generate a nested array. I'm querying the database to try and get all the data from a certain column in my database as an array, but i'm not really quite sure how to do it. Currently it giving me the last row in my database.
Here is my code:
function get_data()
{
$this->db->select('ItemName, QuantitySold');
$query = $this->db->get('transactions');
$results = array();
foreach ($query->result_array() as $row)
{
$row['QuantitySold'];
$row['ItemName'];
}
$results = array(
'name' => 'shirt',
'data' => $row['QuantitySold']
);
$test = json_encode($results);
echo $test;
return $results;
}
It is generating this result:
{"name":"shirt","data":"9"}
And I need it to look something like this:
{'name':'shirt','data':array(1, 2, 3,...)}
Database Structure: http://d.pr/i/cQaW
Rows: http://d.pr/i/8vp2