0

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[]; ???

}

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.