0

This is probably really simple, but I just started using Code Igniter.

I have the following code in a model and want to get the database query array to pass to the controller and then pass it to a page view.

public function view_user($id){
        $this->db->where('userid', $id);
        $query = $this->db->get('users');
        return $query->result_array();
}

What is the code necessary to get the returned array in the controller?

Thanks in advance for your help!

1 Answer 1

2

here you Go with perfact answer

Model code

public function view_user($table,$id)
{
        $this->db->where('userid', $id);
        return $this->db->get($table);
}

Now in controller Call your Method Like

$this->load->model('model_name');
$data['array_name']= $this->model_name->view_user('Tabelname',$id)->result();

If u want to Get Only single row Insted of result write ->row(); in above statement

now load your view and pass the $data as 2nd pararameter

$this->load->view('viewname',$data)

now in your VIEW

Acesss Array Like

  <?php foreach($array_name as $row)?>
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.