Does not show the result of the query

0

I'm trying to make a query that shows all the results of a table with a couple of parameters and then encode them in json, however in the query I do not show the results of the table, and it only brings me back a single result, which can be my mistake, since I do not see it.

This is the code I'm using

$resultado = mysqli_query($connect, "SELECT * FROM 'transacciones' WHERE 'Usercorreo' = '$Username'");

while($array=mysqli_fetch_array($resultado)) {
  $response["ComCorreo"] = $array['ComCorreo'];
  $ComCorreo = $array['ComCorreo'];
  $response["monto"] = $array['monto'];
  $response["fecha"] = $array['fecha'];
  $response["concepto"] = $array['concepto'];
  $comrsql=mysqli_query($connect,"SELECT *  FROM 'comercios' WHERE 'Comcorreo'='$ComCorreo'");
  while($rowid=mysqli_fetch_array($comrsql)) {
    $response["COMERCIONOMBRE"] =$rowid['nombre'];
    $response["COMERCIOLOGO"] =$rowid['logo'];
  }
}
    
asked by Jesus Moran 23.08.2017 в 16:12
source

4 answers

0

This was the way I did it and it worked:

while($array=mysqli_fetch_array($resultado)){
            $temp = array();
            $temp["idTrans"] = $array['idTrans'];
            $temp["ComCorreo"] = $array['ComCorreo'];
            $ComCorreo = $array['ComCorreo'];
            $monto = $array['monto'];
            $monto_bonito = number_format($monto, 2, '.', ',');
            $temp["monto"] = $monto_bonito;
            $temp["fecha"] = $array['fecha'];
            $temp["concepto"] = $array['concepto'];

        //array_push($response["movimientos"], $temp);
        $comrsql=mysqli_query($connect,"SELECT *  FROM 'comercios' WHERE 'Comcorreo'='$ComCorreo'");
                    while($rowid=mysqli_fetch_array($comrsql)){
                        //$comtemp = array();
                        $temp["COMERCIONOMBRE"] =$rowid['nombre'];
                        $temp["COMERCIORIF"] =$rowid['rif'];
                        $response["COMERCIOLOGO"] =$rowid['logo'];
                    array_push($response["movimientos"], $temp);      
                    }

    
answered by 06.09.2017 / 22:05
source
0

You're overwriting the same variable all the time, get yourself a new one and it's done: (The other thing you say I do not understand)

$resultado = mysqli_query($connect, "SELECT * FROM 'transacciones' WHERE 'Usercorreo' = '$Username'");
$misdatos = array()
while($array=mysqli_fetch_array($resultado)) {
  $response["ComCorreo"] = $array['ComCorreo'];
  $ComCorreo = $array['ComCorreo'];
  $response["monto"] = $array['monto'];
  $response["fecha"] = $array['fecha'];
  $response["concepto"] = $array['concepto'];
  $comrsql=mysqli_query($connect,"SELECT *  FROM 'comercios' WHERE 'Comcorreo'='$ComCorreo'");
  while($rowid=mysqli_fetch_array($comrsql)) {
    $misdatos[] = array(
            'COMERCIONOMBRE' => $rowid['nombre'],
            'COMERCIOLOGO' => $rowid['logo'],
    )
  }
}
$mijson = json_encode($misdatos);
    
answered by 23.08.2017 в 16:29
0

Daniel's answer was fine but incomplete, the code after seeing it was as follows:

while($array=mysqli_fetch_array($resultado)){ $response["ComCorreo"] = $array['ComCorreo']; $ComCorreo = $array['ComCorreo']; $response["monto"] = $array['monto']; $response["fecha"] = $array['fecha']; $response["concepto"] = $array['concepto']; echo json_encode($response); $comrsql=mysqli_query($connect,"SELECT * FROM comercios WHERE Comcorreo = '$ ComCorreo' ");                         while ($ rowid = mysqli_fetch_array ($ comrsql)) {                             $ data ["COMERCIONOMBRE"] = $ rowid ['name'];                             $ data ["COMERCIOLOGO"] = $ rowid ['logo'];                             echo json_encode ($ data);                         }         }         

Where in each while I show the json result of the array, with this structure I make a nested query to two tables, and it shows a json that can be recovered from other applications

    
answered by 23.08.2017 в 17:13
0
**iNTENTA HACERLO DE EN ESTA MANERA. Espero te ayude Bendiciones.**

<?php


        require('conexion.php');

        $consultas="SELECT *  FROM alumnos";

        $resultados=$conectahugo->query($consultas);

        while($columnas=$resultados->fetch_assoc()){

        echo $columnas['id'],' ';
        echo $columnas['nombrep'],' ';
        echo $columnas['descripcion'],' ';
        echo $columnas['precio'],' ';


        echo '<br>';
        }

? >

    
answered by 23.08.2017 в 17:23