PHP - FUNCION CON ARRAYS NO DEVUELVE DATOS

 
Vista:
sin imagen de perfil
Val: 79
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

FUNCION CON ARRAYS NO DEVUELVE DATOS

Publicado por Jonathan (40 intervenciones) el 06/01/2020 15:55:58
Estimados

Tengo las siguientes funciones en PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
public function resultados(){
    if(!(empty($_POST['patente']))){
        $patente = $_POST['patente'];
    }
    $sqlQuery = "SELECT * FROM vehiculos WHERE patente='$patente'";
    $resultados = mysqli_query($this->db_conectada , $sqlQuery);
    $totalresultados = mysqli_num_rows($resultados);
    if($totalresultados > 0) {
        while ($fila = mysqli_fetch_assoc($resultados)) {
            $vin = $fila['vin'];
            $marca = $fila['marca'];
            $modelo = $fila['modelo'];
            $motor = $fila['motor'];
            $periodo = $fila['periodo'];
            $combustible = $fila['combustible'];
            $HTML = [$vin,$marca,$modelo,$motor,$periodo,$combustible];
        }
    }else{
        $HTML = ['Sin Datos','Sin Datos','Sin Datos','Sin Datos','Sin Datos','Sin Datos'];
    }
    return $HTML;
}
 
public function cliente(){
    if(!(empty($_POST['rut']))){
        $rut = $_POST['rut'];
    }
    $sqlQuery = "SELECT * FROM clientes WHERE rut='19.064.128-7'";
    $resultados = mysqli_query($this->db_conectada , $sqlQuery);
    $totalresultados = mysqli_num_rows($resultados);
    if($totalresultados > 0) {
        while ($fila = mysqli_fetch_assoc($resultados)) {
            $nombre = $fila['nombre'];
            $telefono = $fila['telefono'];
            $HTML = [$nombre,$telefono];
        }
    }else{
        $HTML = ['Sin Datos','Sin Datos'];
    }
    return $HTML;
}

Mediante Ajax busco pasar las variables obtenidas

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function listado_vehiculos() {
    $('.searchResult').html('<div id="loading">Cargando .....</div>');
    var action = 'fetch_data';
    var patente = document.getElementById("patente").value;
    $.ajax({
        url:"ordenes.php",
        method: "POST",
        dataType: "json",
        data:{ action:action,patente:patente},
        success:function(data){
            $('#vin').val(data.html[0]);
            $('#marca').val(data.html[1]);
            $('#modelo').val(data.html[2]);
            $('#motor').val(data.html[3]);
            $('#periodo').val(data.html[4]);
            $('#combustible').val(data.html[5]);
        }
    });
}
function listado_clientes() {
    var action = 'fetch_data';
    var rut = document.getElementById("rut").value;
    $.ajax({
        url:"ordenes.php",
        method: "POST",
        dataType: "json",
        data:{ action:action,rut:rut},
        success:function(data){
            $('#nombre').val(data.html2[0]);
    $('#telefono').val(data.html2[0]);
        }
    });
}

La funcion resultados si funciona, pero la función clientes no, ahora si yo borro la funcion resultados si funciona la funcion clientes, porque puede estar pasando eso ?, o de que otra forma puedo realizar la busqueda, de antemano muchas gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 1.071
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

FUNCION CON ARRAYS NO DEVUELVE DATOS

Publicado por Yamil Bracho (888 intervenciones) el 06/01/2020 16:24:22
Como sabe la funcion en javascript a cual de las funcione en el backend estas llamando. Porque siempr eusas ordenes.php como url.
Me imagna que en ordenes.php estan las dos funciones. asi que agregarlealgun parametro que te permita distinguir cual estas llamando o separa las dos funciones en su correspondiente archivo php y los colocas como url de la respectiva llamada en javascript
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 79
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

FUNCION CON ARRAYS NO DEVUELVE DATOS

Publicado por Jonathan (40 intervenciones) el 06/01/2020 16:41:29
Pues asi llamo a las funciones

1
2
3
4
5
6
7
8
9
10
$clientes = new Clientes();
if(isset($_POST["action"])){
	$html = $clientes->resultados();
	$html2 = $clientes->cliente();
	$data = array(
		"html"	=> $html,
		"html2" => $html2,
	);
	echo json_encode($data);
}

Por eso en una funcion Ajax dice html y en la otra html2
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 1.071
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

FUNCION CON ARRAYS NO DEVUELVE DATOS

Publicado por Yamil (888 intervenciones) el 06/01/2020 17:58:08
colocale y var_dum($data) antes del echo json_.... a ver qu eiene $data
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar