Skip to content
Advertisement

Codeigniter select where AND

How to do select where and with code igniter ? //select * from item_user where email="myemail@gmail.com" and passwd="123"

function index_get() {
    $email = $this->get('email');
    $passwd = $this->get('passwd');

    $sql = "SELECT * FROM web_user ";

    if ($email != '') {
        $this->db->where('email', $email & 'passwd', $passwd);
        $item_user = $this->db->get('web_user')->result();

    }

    if ($item_user) {
        $this->response([
            'status' => true,
            'message' => 'found',
            'data' => $item_user
        ], REST_Controller::HTTP_OK);
    } else {
        $this->response([
            'status' => false,
            'message' => 'not found',
        ], REST_Controller::HTTP_NOT_FOUND);
    }
}

i think my wrong syntax is around $this->db->where('email', $email & 'passwd', $passwd); please help me, and where to learn this kind of CI stuff easily?

Advertisement

Answer

Hope this helps

 $this->db->where('email', $email);
 $this->db->where('passwd', $passwd);
 $item_user = $this->db->get('web_user')->result();

If you are using GET Method Get the data using this

$email =  $this->input->get('email');

If you are using POST Method Get the data using this

$email = $this->input->post('email');
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement