2

I want to know where I can retrieve the result of a query in Codeigniter.

The code:

$this->db->where('usuario', $this->input->post('drcorreo')); 
$cdb = $this->db->get('usuarios');

How do I save the name of the user from this query in the session class?

2 Answers 2

2

Try this:

### saving in the session ###
$rs = $this->db->where('usuario', $this->input->post('drcorreo'))->get('usuarios');
if($rs->num_rows() > 0){
    $data   = $rs->row_array();     #for a single tuple use result_array() for multiple tuples
    $this->session->set_userdata('usuario', $data['usuario']);  #saving it in session
}

### to retrieve dfrom the session ###
$usuario    = $this->session->userdata('usuario');
Sign up to request clarification or add additional context in comments.

3 Comments

I tried this but it doesn't work. When I try to retrieve the username I watch vale and the name must be alexander. What's wrong?
First echo your query and run it in your phpmyadmin. To echo the query: echo $this->db->last_qeury();. Second, print your $data array and see if you are fetching the correct result from the db. Third, print the session print_r($this->session->all_userdata());.
Yes, it works now. I can watch the username and I can save it in the session table. The problem was that the query I typed was wrong.
0

You can try this:

$result = $this->db->get_where($table, array('username' =>$this->input->post('drcorreo'))); 
$result->result_array();

for documentation you may read it in here Codeigniter

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.