Show Data using keyup (Does not work)

0

I need that when writing in an input of type text, if what I wrote corresponds to a value of the database, the result, which in this case would be the name of a student, is shown in another input of type text . I am entering the data in a modal, but when writing in the input, it does not show me the result (within the same modal). I leave the code in case you know that it is missing or that I should correct, I would appreciate it. I throw this Error:

  

A PHP Error was encountered

Severity:   Notice

Message: Array to string conversion

Filename:   models / mCalendar.php

Line Number:   59

Backtrace:

File:   C: \ xampp \ htdocs \ SAE \ application \ models \ mCalendar.php
Line:   59
Function: _error_handler File:   C: \ xampp \ htdocs \ SAE \ application \ controllers \ cCalendar.php Line: 52
Function:   search_student File: C: \ xampp \ htdocs \ SAE \ index.php Line: 315
Function: require_once Array

Line 59 is echo $ student;

Model (mCalendar)

 public function buscar_estudiante($rut_estu){


  $this->db->select('CONCAT(pnombre, " ",apellido_pa," ", apellido_ma) As estudiante');
  $this->db->from('estudiantes');
  $this->db->where('rut_estu',$rut_estu);
  $estudiante = $this->db->get()->result();

   echo $estudiante;

 }

Controller (cCalendar)

 public function buscar_estudiante(){


    $rut_estu=  $this->input->post('rut_estu');
    $estudiante = $this->mCalendar->buscar_estudiante($rut_estu);

}

javascript within the View

 $("#rut_estu").keyup(function(){

    var parametros = {

            "rut_estu" :$("#rut_estu").val(),

           }

      $.ajax({
            data:  parametros,
            url:   '<?php echo base_url();?>cCalendar/buscar_estudiante',
            type:  'post',
            beforeSend: function () {

                $("#nombre_estu").val();

            },
            success:  function (response) {
                $("#nombre_estu").val(response); 

            }
      });


   });
    
asked by Kvothe_0077 25.09.2017 в 23:00
source

4 answers

1

I guess you're using jQuery (for the% share_co%) and CodeIngniter (for the% share_co%). If both are true, then you must change your code by:

$("#rut_estu").keyup(function(){

Well, you were missing the $.ajax symbol

As for PHP, CodeIgniter returns the complete object when executing $this->db->select , so you should change the code by:

echo $estudiante[0]->estudiante;

Well, what you want is the value of the column $ (according to your query)

    
answered by 26.09.2017 / 00:28
source
0

rut_estu that you go through the parameter is the name, not the ID, to look for them by rut_estu

 ("input[name='rut_estu']").keyup(function(){

var parametros = {

        "rut_estu" :$("input[name='rut_estu']").val(),

       }

  $.ajax({
        data:  parametros,
        url:   '<?php echo base_url();?>cCalendar/buscar_estudiante',
        type:  'post',
        beforeSend: function () {

            $("input[name='rut_estu']").val();

        },
        success:  function (response) {
            $("input[name='nombre_estu']").val(response); 

        }
  });

});

to check it use developer tools

    
answered by 25.09.2017 в 23:10
0

name_estu is the name / id of an input, and is in javascript, this is done before with php alone, without codeigniter and it works fine, although it uses a while, I do not know how it would be in this case .... this is the code with php only for a previous system that I made.

  function buscar_cliente3(){

        $rut_usu=$this->rut_usu;
        $sql="SELECT usuarios.rut_usu, usuarios.apellido_pa
            FROM usuarios
            INNER JOIN perfiles ON usuarios.id_per=perfiles.id_per
            INNER JOIN region ON usuarios.id_reg=region.id_reg
            INNER JOIN provincia ON usuarios.id_pro=provincia.id_pro
            INNER JOIN comuna ON usuarios.id_com=comuna.id_com
            WHERE usuarios.rut_usu = '$rut_usu'";
            $resultado = mysqli_query($this->conexion, $sql);
            $pnombre="";
            $snombre="";
            $apellido_pa="";
            $apellido_ma="";
            while ( $datos=mysqli_fetch_array($resultado) ){
                $apellido_pa =$datos["apellido_pa"];

            }

                        echo $apellido_pa;

       }
    
answered by 25.09.2017 в 23:56
0

Solved, thanks to the community for their help, the model should be this way

public function buscar_estudiante($rut_estu){


  $this->db->select('CONCAT(pnombre, " ",apellido_pa," ", apellido_ma) As estudiante');
  $this->db->from('estudiantes');
  $this->db->where('rut_estu ',$rut_estu);
  $estudiante = $this->db->get()->row();



   //return $estudiante;

   echo $estudiante->estudiante;

}
    
answered by 26.09.2017 в 16:59