How to add table in php?

1

Good afternoon, I have a code that loads a bd table, what I'm looking for is to take advantage of the cycle to be able to add and send it in an input.

  <table class="table table-striped"> 
            <thead>
              <tr>
                <th width="100">ID</th>
                <th width="250">Codigo</th>
                <th width="200">Item</th>
                <th width="200">Precio</th>
              </tr>
            </thead>
            <tbody>
            <!-- Generamos el listado vaciando las variables de la consulta en la tabla -->
              <?php 
              while($persona = $consulta->fetch_assoc()) //Creamos un array asociativo con fetch_assoc 
               //$precio_venta=$persona["precio"];
              { 
              ?>
                <tr>
                  <td><?php echo $persona['id']; ?></td>
                  <td><?php echo $persona['codigo']; ?></td>
                  <td><?php echo $persona['item']; ?></td>
                  <td><?php echo $persona['precio']; ?></td>
                </tr>

              <?php
              }
              ?>
            </tbody>
          </table>
    </div>
</div>
    
asked by juan perez 20.12.2017 в 18:17
source

1 answer

2
 <table class="table table-striped"> 
            <thead>
              <tr>
                <th width="100">ID</th>
                <th width="250">Codigo</th>
                <th width="200">Item</th>
                <th width="200">Precio</th>
              </tr>
            </thead>
            <tbody>
            <!-- Generamos el listado vaciando las variables de la consulta en la tabla -->
              <?php 
             $precio_venta =0;
              while($persona = $consulta->fetch_assoc()) //Creamos un array asociativo con fetch_assoc 
               $precio_venta += $persona["precio"];   //justamente aqui y luego puedes hacer un echo $precio_venta;
              { 
              ?>
                <tr>
                  <td><?php echo $persona['id']; ?></td>
                  <td><?php echo $persona['codigo']; ?></td>
                  <td><?php echo $persona['item']; ?></td>
                  <td><?php echo $persona['precio']; ?></td>
                </tr>

              <?php
              }
              ?>
            </tbody>
          </table>
    </div>
</div>
    
answered by 20.12.2017 / 18:27
source