How to create an Array with a While of the DB?

1

How are you? I'm trying to get help with the following >

I have this Array:

   $ComprobanteItem_1 = array(
                  "Cantidad" => 1,
                  "Detalle" => "Producto Uno",
                  "Codigo" => "CODPROD",
                  "IVA" => 21,
                  "PrecioUnitario" =>100,
                  "Total" => 121,
                  "Gravado" => true,
                  "Bonificacion" => 0
                  ),

I need a While or some type of Loop, I complete the fields and increase the identifier CheckBox_X where X would be the Array Number. All based on the query made in the database. There can be 1 like 20 Items in repeating this code fragment and I can not get it to work. the Gross Code would have to stay that way

$items = array(
                $ComprobanteItem_1 = array(
                      "Cantidad" => 1,
                      "Detalle" => "Producto Uno",
                      "Codigo" => "CODPROD",
                      "IVA" => 21,
                      "PrecioUnitario" =>100,
                      "Total" => 121,
                      "Gravado" => true,
                      "Bonificacion" => 0
                      ),
                $ComprobanteItem_2 = array(
                      "Cantidad" => 1,
                      "Detalle" => "Producto Uno",
                      "Codigo" => "CODPROD",
                      "IVA" => 21,
                      "PrecioUnitario" =>100,
                      "Total" => 121,
                      "Gravado" => true,
                      "Bonificacion" => 0
                      ),
                 );

How can I do it ?? thanks !!!

    
asked by GusGeek 01.10.2017 в 00:36
source

1 answer

0

I already managed to solve it, the answer was like that.

      $i = 0;

          while ($vhoy = mysqli_fetch_array($ventatabla)) {

          // ARRAY DONDE SE GENERA A PARTIR DE UN $i 0

               $fic[$i] = array(
                "Cantidad" => $vhoy['cantidad'],
                "Detalle" => $vhoy['nombre'],
                "Codigo" => $vhoy['idficha'],
                "PrecioUnitario" =>$vhoy['costodeventa'],
                "Total" => $vhoy['costodeventa'],
                "Gravado" => true,
                "Bonificacion" => 0
                );


           // CUANDO FINALIZA LA SECUENCIA ANTERIOR $i HACE SUMA + 1
           // DE ESTA FORMA EL INDICE DEL ARRAY ($fic[$i]) SE AUTO
           // INCREMENTA HACIENDO QUE EL INDICE FINAL SEA UNICO


              $i++;
          }


print "<pre>";
print_r($fic);
print "</pre>";


$items = array($fic); // ARRAY LIMPIO
    
answered by 01.10.2017 в 03:09