“模态”按钮仅显示数据库中的第一个用户

时间:2016-10-23 18:59:44

标签: php modal-dialog

我正在创建一个数据库,我正在尝试创建一个显示用户票证信息的按钮。每当我点击按钮时,我想让它说出个人姓名,但无论我点击哪个用户,它都只显示第一个用户名,而不是我点击的按钮的人的姓名。这是模态按钮的代码

$count = mysqli_num_rows($query);
if($count ==0){
        $output = 'There was no search result!';
}else{

    $counter=0;
    while($row = mysqli_fetch_array($query)){
        $fname = $row['f_name'];
        $lname = $row['l_name'];
        $email = $row['email'];
        $password = $row['password'];
        $userID = $row['userID'];
        $status = $row['status'];
        if($status == 'Active'){
            $classStatus='label-success';
        }else{
                $classStatus='label-danger';
        }
        $output.='<tr>
                    <td>
                        <a class="tv8" href="#"><img src="images/tv8.png" alt="Send TeamView 8 Link to Email" style="width:30px;height:30px;"></a>
                        <img src="images/cert.png" alt="Send Certification to Email" style="width:30px;height:30px;"> 
                    </td>
                    <td>' . $fname . ' ' . $lname . '</td>
                    <td id='.++$counter.'>' . $email. '</td>
                    <td>' . $userID . '</td>
                    <td>' . $password . '</td>

                    <td><h4><span class="label ' .$classStatus.'">'.$status.'</span></h4></td>   

<td><button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#myModal">View</button></td><!-- Trigger the modal with a button -->


<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Ticket Information</h4>
      </div>
      <div class="modal-body">
        <p>' . $fname . ' ' . $lname . ' ticket info will be found here.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

当我点击按钮而不只是数据库中列出的第一个人时,如何让此代码显示不同的人名?

1 个答案:

答案 0 :(得分:0)

使用您设置的$ counter变量来区分Mymodal ID。将您的按钮更改为:

<button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#myModal' . $counter . '">

和你的模态:

<div id="myModal' . $counter . '" class="modal fade" role="dialog">

我自己不会这样做,但这应该可以解决你的问题