Welcome Guest, Not a member yet? Register   Sign In
db active record
#1

[eluser]dan.syme[/eluser]
in my controller i have the following function

function all()
{
$data['query'] = $this->db-get('activities');
$this->load>view('activity_response', $data);
}

I want to push the query result into an array and then json_encode. Do i have to use a foreach here or does the query automatically push to any array, or do I need to use a regular mysql_fetch_array?

Thanks,
#2

[eluser]cahva[/eluser]
Yes you have to use foreach but no, you dont have to use mysql_fetch_array. Just use:
Code:
$myarr = array();
foreach ($query->result_array() as $row)
{
    $myarr[] = $row;
}
// After do what you want with the array. Create a json for example.
#3

[eluser]dan.syme[/eluser]
yep, figured it out, thanks mate.




Theme © iAndrew 2016 - Forum software by © MyBB