I have a database table named users with some keys 'userid, username, age', and also there are some records in this table, I want to get them like json, please look at this
{
"status":"1",
"msg":"success",
"userlist":[
{
"userid":"1",
"username":"chard",
"age":"22"
},
{
"userid":"2",
"username":"rose",
"age":"21"
},
{
"userid":"3",
"username":"niki",
"age":"25"
}
]
}
user_model.php file, i write
function get_users()
{
$query = $this->db->get('users');
return json_encode($query->row_array());
}
user.php controller file, i write
function index_get()
{
$this->load->model('users_model');
$query = $this->users_model->get_users();
echo $query;
}
I can get the result, but it's a wrong result, only this
{ "userid":"1", "username":"chard", "age":"22" }
so how should I fix this?