Unknown column when using WHERE (ERROR) codeigniter

1

I am trying to show a value of the Database in an input, however I get the following error. Why is this happening?

A Database Error Occurred

Error Number: 1054

Unknown column '17811942-4' in 'where clause'

SELECT 'horario'.'hrs_ini' FROM 'horario' JOIN 'usuarios' ON 'horario'.'rut_usu' = 'usuarios'.'rut_usu' WHERE 'usuarios'.'rut_usu' = '17811942-4' AND 'horario'.'lunes' = 'ATTE'. 'ESTUDIANTES'

Filename: C:/xampp/htdocs/SAE/system/database/DB_driver.php

Line Number: 691

Query in the database

Model

public function lunes(){


$this->db->select('horario.hrs_ini');
$this->db->from('horario');
$this->db->join('usuarios','horario.rut_usu = usuarios.rut_usu');
$this->db->where('usuarios.rut_usu=17811942-4');
$this->db->where('horario.lunes=ATTE. ESTUDIANTES');
$start_lunes = $this->db->get();


if($start_lunes->num_rows() > 0 ){

    return $start_lunes->result();

    }

}

Controller

public function index(){


        $this->load->view('layouts/header.php');
        $this->load->view('layouts/menu.php');


        $this->load->model('mCalendar');
        $data['start_lunes'] = $this->mCalendar->lunes();
        $data['usuarios'] = $this->mCalendar->get_usuarios();
        $data2['motivos'] = $this->mCalendar->get_motivos();
        $this->load->view('usuarios/vConsulta_Horarios.php',$data,$data2);
        $this->load->view('layouts/footer.php');




}
    
asked by CristianOx21 04.10.2017 в 16:23
source

2 answers

1

You are setting the wrong values in the where, it should be like this:

$this->db->where('usuarios.rut_usu','XXXXXXXX-X'); $this->db->where('horario.lunes','ATTE. ESTUDIANTES');
    
answered by 04.10.2017 / 16:29
source
1

The error is in this line:

$this->db->where('usuarios.rut_usu=17811942-4');

You are trying to find where the value of the column 'users.rut_usu' is equal to the value of column '17811942-4'. The correct thing would be:

$this->db->where('usuarios.rut_usu','17811942-4');

This looks for where the value of the column 'users.rut_usu' is equal to '17811942-4'

Look at this docu: link

    
answered by 04.10.2017 в 16:34