1

I'm having trouble understanding how to get data (single row) from a model query into a controller function in codeigniter. I've searched the stack overflow posts, but no luck. I have a query in a model like this:

function login($email, $sha1Pass) {
    $loginArray = array('email' => $email, 'pw' => $sha1Pass);
    $this->db->select('lid, email, pw');
    $this->db->from('login');
    $this->db->where($loginArray);
    $query = $this->db->get();
    return $query->row();
}

There will only be 1 returned row [lid, email, pw]

I then have a controller that calls this model query.

$report['row'] = $this->LoginCheck->login($email, $encp); 

What I need is 2 fields from the database from the row and assign them to a variable like this:

$lid = $report['lid'];
$email = $report['email'];

lid and email are the fields from the database.

4 Answers 4

1

You can access them like:

$lid = $report['row']->lid;
$email = $report['row']->email;
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

Login_model

public function auth($nm,$pwd)
{
    $this->db->select('uname,password');
    $q1=$this->db->get_where('user_details',array('uname'=>$nm,'password'=>$pwd));
    return $q1->row();
}

//you can call this method from controller like

$data['query']=$this->Log_Model->auth($unm,$pswd);

//And you can create session variable like,

$this->session->set_userdata('uname',$data['query']->uname);

Comments

0

If you view set this

$lid = $report['lid'];
$email = $report['email'];

Then add some on model to get query as

function login($email, $sha1Pass) {
$loginArray = array('email' => $email, 'pw' => $sha1Pass);
$this->db->select('lid, email, pw');
$this->db->from('login');
$this->db->where($loginArray);
$query = $this->db->get();
return $query->row_array();
}

just set row() to row_array()

Comments

0
  $data = array(
        'username' => $_POST['fullname'],
        'useremail' => $_POST['email'],
        'social_login_id' => $_POST['bq_user_id'],
        'social_login_type' => $loginType,
        'login_status' => 'online',
        'is_active' =>1,
    );
    $this->db->insert($this->TABLE, $data);

1 Comment

Hi, This may answer the question, please provide some explanation of your code.

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.