lets say the query from my controller is $query.
how to display the data other than using this kind of code?
foreach($query as $row){
echo $row->student_id;
}
any other than this coz the query only have one row
any way that can i access the returned array like this?
$query['student_id'];
let's say your table have the following fields
student_id and student_name
have your model or controller return only one row.
function get_first_student() {
$query = this->db->select('*')->from('student')-where('student_id','1')->limit(1);
$data['stuff'] = $query->row_array(); // or $query->row() which returns an object
$this->load->view('whatever',$data)
}
then in your view
<p>student name: <?= $stuff['student_name'] ?> </p>
<p>student id: <?= $stuff['student_id'] ?> </p>
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