I have the following query, which returns a single row.
MODEL:
function get_guide_first(){
$this->db
->select('*')
->from('guides_entries')
->order_by("guide_name", "asc")
->limit(1, 0)
->join('guides_content', 'guides_content.guide_id = guides_entries.guide_id');
$query = $this->db->get();
return $query->result_array();
}
Here is my controller:
CONTROLLER:
public function get_first_guide(){
$page_data['guide']=$this->guides_model->get_guide_first();
$this->load->view('guidepage', $page_data);
}
I then run a foreach() loop in my view (or controller sometimes).
VIEW:
foreach($guide as $row){
echo $row['guide_content'];
$activecat=$row['guide_slug'];
}
Now what I would ideally like to do is return an array back from my model but even using:
return $query->row();
returns an object rather than an array.
1)How can I return this row as a 2d array?
e.g. so that I could echo a result in the controller as guide[‘col_name’] rather than guide()->col_name.
2)how would I pass the object to my view so that I could use $guide->col_name from there (I would need to pass this along eith the $page_data array)
If i’m reading your question right: You can use
row_arrayinstead ofresult_arrayI think:
return $query->result_array();returns an
to return just an associated array.
row array will return