$this->db->select('id, user_id')->from('be_users')->where('id',$user_id);
$data['user_individual'] = $this->db->get();
If this is my db query, how do I get an array of one db row...
ie. I want to do something like $data['user_individual']['id']->format_as_array
...
CodeIgniter provides several methods to perform on query results.
See here: https://codeigniter.com/user_guide/database/results.html
result()
returns an array of PHP objects.
row()
returns a single PHP object for that row.
result_array()
returns an array of arrays.
row_array()
returns a single array for that row.
row()
and row_array()
optionally take a parameter which is the number of the row you'd like to return.
Beyond this, it's difficult to tell exactly what you're asking for. You should be able to get your data out exactly as you like with these methods.
Edit:
Incidentally, the way to access these methods is through the query object returned from the $this->db->get()
call:
$query = $this->db->get();
$rows = $query->result(); //array of objects
$rows_array = $query->result_array(); //array of arrays
$row = $query->row(); //single object
$row_array = $query->row_array(); //single array
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With