简体   繁体   English

使用mysql和php在bootstrap模式中的多个结果

[英]multiple results with mysql and php in modal of bootstrap

I am trying to print in the modal the information of the selected user but only the first row is printed in the modal. 我试图在模态中打印所选用户的信息,但只有第一行打印在模态中。

I am using PHP with MySQL but it is not working. 我正在使用PHP与MySQL,但它无法正常工作。 I don't understand why it prints only the first row. 我不明白为什么它只打印第一行。

Please help to resolve my issue. 请帮忙解决我的问题。

This is the php code: 这是php代码:

include ("conex.php");

$query = "SELECT * FROM empleado WHERE cargo='personal'";
$datos=mysqli_query($conex,$query);

echo "<div class='tables'>";
echo "<h3 class='title1'>Listado de Empleados :</h3>";
echo "<div class='panel-body widget-shadow'>";
echo "<table class='table'>";
echo "<button class='btn btn-success add-prod'>
                         <span class='fa fa-plus'></span>  
                                  Agregar Empleado
                         </button>";

echo "<thead><tr><th>Rut</th><th>Nombre</th><th>Apellido</th><th class='action'>Accion</th></thead>";



while($fila=mysqli_fetch_assoc($datos))
    {   


        echo "<tbody>";
        echo "<tr title='informacion detallada' class='selector-empleado' data-toggle='modal' data-target='#infodetallada'>";
        echo "<td>".$fila["rut"]."</td>";
        echo "<td>".$fila["nombre"]."</td>";
        echo "<td>".$fila["apellido"]."</td>";
        echo "<td class='buttons-admin'><button title='modificar empleado' class='btn btn-primary btn-admin1'><span class='fa fa-refresh'></span></button>
        <button  onClick='window.location=\"eliminarempleado.php?rut=".$fila["rut"]."\";'/ title='eliminar empleado' class='btn btn-danger btn-admin2'>
        <span class='fa fa-times'></span></button></td>";
        echo "</tr>";
        echo "</tbody>";





    echo "<div class='modal fade' id='infodetallada' role='dialog'>";
    echo  "<div class='modal-dialog'>";

    echo  "<div class='modal-content'>";
    echo  "<div class='modal-header'>";
    echo   "<button type='button' class='close' data-dismiss='modal'>&times;</button>";
    echo    "<h4 class='modal-title'>Informacion detallada :</h4>";
    echo "</div>";
    echo "<div class='modal-body'>";
    echo  "<b>Rut : </b>" .$fila["rut"]."<br>";
    echo  "<b>Nombre : </b>" .$fila["nombre"]."<br>";
    echo  "<b>Apellido : </b>" .$fila["apellido"]."<br>";
    echo  "<b>Cargo : </b>" .$fila["cargo"]."<br>";
    echo  "<b>Correo : </b>" .$fila["correo"]."<br>";
    echo  "<b>Contraseña : </b> ************";
    echo "</div>";
    echo "<div class='modal-footer'>";
    echo "<button title='modificar empleado' class='btn btn-primary'><span class='fa fa-refresh'></span> Modificar</button>";
    echo "<button onClick='window.location=\"eliminarempleado.php?rut=".$fila["rut"]."\";'/ title='eliminar' class='btn btn-danger'><span class='fa fa-times'></span> Eliminar </button>";
    echo  "<button type='button' class='btn btn-default' data-dismiss='modal'>Cerrar</button>";
    echo "</div>";
    echo "</div>";

    echo "</div>";
    echo "</div>";




    }

        echo "</table>";
        echo "</div>";
        echo "</div>";
        echo "</div>";
        echo "<div class='clearfix'></div>";
        echo "</div>";
        echo "</div>";

    mysqli_close($conex);

You just have to make couple of minor changes. 你只需做一些小改动。

Append some unique id to the data-target attribute in the clickable element, so that it is unique for each record 在可点击元素的data-target属性中附加一些唯一ID,以使其对每条记录都是唯一的

<tr title='informacion detallada' class='selector-empleado' data-toggle='modal' data-target='#infodetallada".$fila['rut']."'>

Append same unique id to the id attribute of the modal, so that it is same to the respective clickable element. 将相同的唯一id附加到模态的id属性,以使其与相应的可单击元素相同。

<div class='modal fade' id='infodetallada".$fila['rut']."' role='dialog'>

I assumed that $fila['rut'] will be unique for each of the records. 我认为$fila['rut']对于每个记录都是唯一的。 If it is not so, then you can use some other unique elements. 如果不是这样,那么您可以使用其他一些独特的元素。

Issue: Each model box should be connected on its own unique ID. 问题:每个模型框应按其自己的唯一ID进行连接。 It should have unique ' data-target ' in the clickable element & ' id ' in the respective modal. 它应该在可点击元素中具有唯一的“ data-target ”,并且在相应的模态中具有“ id ”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM