Paul Noris Paul Noris - 7 months ago 43
PHP Question

Bootstrap Data-toggle not working on PHP using a "while "

I have a problem whith my " Bootstrap Collapse" . My query display only the fist $ID_Producto of all my rows.

<?php

$Consulta_Productos = $Conexion ->query( "SELECT * FROM productos ORDER BY Producto_Categoria");
while($Fila_Productos = $Consulta_Productos->fetch_assoc())
{
$ID_Producto = $Fila_Productos['ID_Producto'];
?>

<span data-toggle="collapse" data-target="#demo">Show ID <?php echo $ID_Producto ?></span>
<div id="demo" class="collapse">
<?php echo $ID_Producto; ?>
</div>
<br>

<?php
}
?>

Jah Jah
Answer

your data-target="#demo" and id="demo" are the same for all the products.

try this

<?php

        $Consulta_Productos = $Conexion ->query( "SELECT * FROM productos ORDER BY Producto_Categoria");
        while($Fila_Productos = $Consulta_Productos->fetch_assoc())
        {
            $ID_Producto = $Fila_Productos['ID_Producto'];
        ?>

            <span data-toggle="collapse" data-target="#demo<?php echo $ID_Producto; ?>">Show ID <?php echo $ID_Producto ?></span>
            <div id="demo<?php echo $ID_Producto; ?>" class="collapse">
                <?php echo $ID_Producto; ?>
            </div>
            <br>

        <?php
        }
        ?>