1

buen día, espero estén bien. estoy teniendo un pequeño problema con mi código, estoy haciendo un crud de datos con php y mysql y hasta el momento todo bien, pero al momento de insertar mas registros estos se desplazan hacia los lados y no hacia abajo como pensé que sería. me podrían ayudar? cualquier ayuda será bien recibida. :)

así se ven los registros introducir la descripción de la imagen aquí

y agrego el código donde traigo los datos de la base de datos

  <div class="container">
        <div class="row">
            <div class="col">
            <br><br><br>
                <button type="button" class="btn btn-primary float-end" id="nuevo">
                    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                    agregar
                </button>
            <br>
            <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>id</th>
                        <th>Nombre</th>
                        <th>Precio</th>
                        <th>Cantidad</th>
                        <th>Existencia</th>

                    </tr>
                </thead>

                <tbody>
                    <tr>
                    <?php
                        $peticion = "SELECT * FROM producto"; 
                        $validacion = mysqli_query($conexion,$peticion); 
                        while($muestra = mysqli_fetch_array($validacion)){
                        ?>
                        <td><span id="val1"><?php echo $muestra['Id'];?></span></td>
                        <td><span id="val2"><?php echo $muestra['nombre'];?></span></td>
                        <td><span id="val3"><?php echo $muestra['precio'];?></span></td>
                        <td><span id="val4"><?php echo $muestra['descripcion'];?></span></td>
                        <td><span id="val5"><?php echo $muestra['disponible'];?></span></td>

                        <td>
                            <button type="button" class="btn btn-warning" id="cambiar"> Cambiar
                                <span class="glyphicon glyphicon-pencil" aria-hidden="true">
                                </span>
                            </button>
                        </td>

                        <td>
                        <button type="button" class="btn btn-danger" 
                        id="btn_eliminar" onclick="eliminar()"> Eliminar
                                <span class="glyphicon glyphicon-remove-circle" aria-hidden="true">
                                </span>
                            </button>
                        </td>
                        
                        <?php }
                         ?>
                    </tr>
                </tbody>
            </table>
            </div>
        </div>
    </div>
</div>

trate cerrando los php con ; pero no dio resultado :C

2
  • @AntonioGalicia ciertoooo muchas gracias :) ya se soluciono el 25 ene. a las 20:33
  • baja una línea al cierre de llaves <?php } ?>, debajo del </tr> el 25 ene. a las 20:36

1 respuesta 1

1

El problema esta en la estructuración de tu tabla, el código PHP, en este caso el ciclo while debería de ir antes del TR, para que en cada ciclo te genere una fila nueva.

<div class="container">
  <div class="row">
    <div class="col">
      <br><br><br>
      <button type="button" class="btn btn-primary float-end" id="nuevo">
                    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                    agregar
                </button>
      <br>
      <div class="table-responsive">
        <table class="table table-hover">
          <thead>
            <tr>
              <th>id</th>
              <th>Nombre</th>
              <th>Precio</th>
              <th>Cantidad</th>
              <th>Existencia</th>

            </tr>
          </thead>

          <tbody>
            <?php
             $peticion = "SELECT * FROM producto"; 
             $validacion = mysqli_query($conexion,$peticion); 
             while($muestra = mysqli_fetch_array($validacion)){
              ?>
              <tr>

                <td><span id="val1"><?php echo $muestra['Id'];?></span></td>
                <td><span id="val2"><?php echo $muestra['nombre'];?></span></td>
                <td><span id="val3"><?php echo $muestra['precio'];?></span></td>
                <td><span id="val4"><?php echo $muestra['descripcion'];?></span></td>
                <td><span id="val5"><?php echo $muestra['disponible'];?></span></td>

                <td>
                  <button type="button" class="btn btn-warning" id="cambiar"> Cambiar
                                <span class="glyphicon glyphicon-pencil" aria-hidden="true">
                                </span>
                            </button>
                </td>

                <td>
                  <button type="button" class="btn btn-danger" id="btn_eliminar" onclick="eliminar()"> Eliminar
                                <span class="glyphicon glyphicon-remove-circle" aria-hidden="true">
                                </span>
                            </button>
                </td>
              </tr>
              <?php }
              ?>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.