I have already asked two questions before and I am still looking for a way to solve it and I think I found it in this one, only now I do not know how to show all the ID indexes of my JSON first, this is how I perform the query of my JSON:
$sql = "SELECT * FROM PedidosAlmacen WHERE Estado NOT IN ('Ingresados En Sucursal','En Transito a Sucursal','Recibido En Sucursal') AND ParaAlmacenID = '$ID_almacen' ORDER BY Fecha ASC";
$result = mysqli_query($con, $sql);
while ($row = mysqli_fetch_assoc($result)) {
$productos=json_decode($row['Productos'],true);
var_dump($productos);
}
what it throws me is: array(1) { [0]=> array(3) { ["id"]=> string(3) "557" ["quantity"]=> string(1) "1" ["description"]=> string(19) "3 IN 1 MOTORCYCLE DESIGN" } } array(1) { [0]=> array(3) { ["id"]=> string(3) "557" ["quantity"]=> string (1) "1" ["description"]=> string(19) "3 IN 1 MOTORCYCLE DESIGN" } } array(2) { [0]=> array(3) { ["id"]=> string( 3) "557" ["quantity"]=> string(1) "1" ["description"]=> string(19) "3 IN 1 MOTORCYCLE DESIGN" } [1]=> array(3) { [" id"]=> string(3) "558" ["quantity"]=> string(1) "1" ["description"]=> string(18) "3 IN 1 SAM DESIGN" } } array(2) { [0]=> array(4) { ["id"]=> string(3) "557" ["code"]=> string(4) "1002" ["quantity"]=> string(1) "1" ["description"]=> string(19 ) "3 IN 1 MOTORCYCLE DESIGN" } [1]=> array(4) { ["id"]=> string(3) "558" ["code"]=> string(4) "1003" ["quantity "]=> string(1) "1" ["description"]=> string(18) "3 IN 1 SAM DESIGN" } }["description"]=> string(18) "3 IN 1 SAM DESIGN" } }["description"]=> string(18) "3 IN 1 SAM DESIGN" } }
Now knowing that I did the following:
$sql = "SELECT * FROM PedidosAlmacen WHERE Estado NOT IN ('Ingresados En Sucursal','En Transito a Sucursal','Recibido En Sucursal') AND ParaAlmacenID = '$ID_almacen' ORDER BY Fecha ASC";
$result = mysqli_query($con, $sql);
$i=0;
while ($row = mysqli_fetch_assoc($result)) {
$productos=json_decode($row['Productos'],true);
echo $productos[$i]["id"],$productos[$i]["cantidad"];
$i++;
}
I thought of putting an $i so that it increments and returns all but it only brings the first ones: 5571 the ID and its quantity should I use a foreach or some cycle to go through it before it ends?, I say what I would like is that in the main while cycle the first JSON is fetched ( { [0]=> array(3) { ["id"]=> string(3) "557" ["quantity"]=> string(1) "1" ["description"] => string(19) "3 IN 1 MOTORCYCLE DESIGN" } } )
previous questions:
Access all the indexes of my Array from a query With PHP AND MySQL
$products is an array made up of arrays in each loop that you're not looping through. So change this:
For this:
in this way we correctly traverse the subarrays contained in each array in each cycle.
The $i thing is not necessary nor does it work well in this case.
Let us know if it works for you now.