Data is not printed with the json_encode

1
<?php
include ("connex.php");


$sql = "Select item_parent.id_item_parent, item_parent.html_item_parent,
  item_parent.km_cambio_item_parent, item_parent.nombre
From parent_tipo left Join
  item_parent On item_parent.id_parent_tipo = parent_tipo.id_parent_tipo
Where parent_tipo.id_parent_tipo = 1 And item_parent.km_cambio_item_parent <=
 10000";

$result = $conn->query($sql);
$total = array();

if ($result->num_rows > 0) {        
    foreach ($conn->query($sql) as $fila ) {
         $total[] = $fila;
    }
    print json_encode(array("res"=>"ok" , "total"=>$total));

} else {
    print json_encode(array("res"=>"bad" , "msj"=>"No hay coincidencias"));
}

$conn->close();

?>
    
asked by Jhonatan Avila Garcia 25.10.2016 в 13:31
source

1 answer

1

Replaces this:

foreach($conn->query($sql) as $fila ) {
   $total[] = $fila;
}

Because of this:

while($result_row = $result->fetch_object()) {
   $total[] = $result_row;
}

Also, check that the query is done correctly.

    
answered by 29.10.2016 в 16:47