WebService PHP MySQL make two queries

1

I have this WebService in php and MySQL and the intention is to do the $ query2 (which is an update) and then execute the $ query that is a SELECT.

As I see in phpMyAdmin you are running the UPDATE, but the client is not receiving the SELECT. I have checked the phpMyAmdin queries so I will not put the SQL statement as they are correct, unless you ask for it.

PHP Code:

$consulta1 = $_POST["consulta"];
$consulta2 = $_POST["consulta2"];

$resultado2 = mysqli_query($mysqli,$consulta2);
        if ($resultado2) 
        {
            mysqli_free_result($resultado2);
            $resultado= mysqli_query($mysqli,$consulta);
            $arraySalida = array();
            while($registro = mysqli_fetch_assoc ($resultado) ):
                $cadena = "{$registro['nom']};{$registro['per']};{$registro['lug']};{$registro['est']};{$registro['hEnt']};{$registro['hR']};{$registro['hE']};{$registro['hC']};{$registro['obs']};{$registro['pri']};{$registro['idI']};{$registro['ref']};{$registro['fra']};{$registro['eq']};{$registro['dificultad']}";
                 $arraySalida[]= $cadena;
            endwhile;

            echo implode("<",$arraySalida);  

            mysqli_free_result($resultado);
        } 

The problem that I have detected is that once it does a mysqli_query and does not do the other, I tried to do the mysqli_query of the UPDATE before the echo implode () and it updates the database but does not send me the select of the echo implode (). And if I only do the SELECT I receive the data in the client

    
asked by wiki 02.10.2018 в 13:04
source

1 answer

1

This solution works for me:

$consulta1 = $_POST["consulta"];
$consulta2 = $_POST["consulta2"];
//$consulta = "SELECT nom,per,lug,est,hEnt,hR,hE,hC,obs,pri,idI,ref,fra,eq,dificultad,ordenEv FROM EvaPruThyssen WHERE lug ='EXPO TEMPORAL SALA 1' ORDER BY ordenEv ";
$resultado= mysqli_query($mysqli,$consulta1);
        $arraySalida = array();
        while($registro = mysqli_fetch_assoc ($resultado) ):
     $cadena = "{$registro['nom']};{$registro['per']};{$registro['lug']};{$registro['est']};{$registro['hEnt']};{$registro['hR']};{$registro['hE']};{$registro['hC']};{$registro['obs']};{$registro['pri']};{$registro['idI']};{$registro['ref']};{$registro['fra']};{$registro['eq']};{$registro['dificultad']}";
                 $arraySalida[]= $cadena;
        endwhile;
        //echo $consulta;

        echo implode("<",$arraySalida);  


        mysqli_free_result($resultado);
$resultado = mysqli_query($mysqli,$consulta2);
if ($resultado) 
{
     $correcto ="1";
     //echo $consulta;
} 
mysqli_free_result($resultado);
    
answered by 02.10.2018 / 14:04
source