duanpang5583 2017-06-11 18:59
浏览 45
已采纳

使用mysql和php在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. I don't understand why it prints only the first row.

Please help to resolve my issue.

This is the php code:

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);
  • 写回答

1条回答 默认 最新

  • doupo1890 2017-06-12 04:20
    关注

    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

    <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.

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

    I assumed that $fila['rut'] will be unique for each of the records. 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. It should have unique 'data-target' in the clickable element & 'id' in the respective modal.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮