Reputation: 979
I use codeigniter and I want to return from model to controller the following variables only $a, $b, $c, $d instead of the whole row but I am not sure if I wrote the code correctly. Could you please have a look at it.
if ($query->num_rows() == 1){
$row= $query->row_array();
$a = $row['a'];
$b= $row['b'];
$c= $row['c'];
$d= $row['d'];
return $query->result(); // return $row[]; ???
}
Upvotes: 0
Views: 32
Reputation: 12039
Try something like below
$row = $query->row();
return array('a' => $row->a, 'b' => $row->b, 'c' => $row->c, 'd' => $row->d);
//$row->a, here a is column name of DB table
Upvotes: 1