在模态窗口中显示和编辑mysqli记录

时间:2016-07-06 09:16:19

标签: php html modal-dialog

我从MySQL表中提取记录并将其输出到我的网页上的表格中。现在我需要能够编辑我试图通过在每行末尾放置一个编辑按钮来完成的记录,然后打算在我的bootstrap模式中打开记录细节。

可悲的是,这不起作用,因为传递的变量全部用于查询记录的最后一个条目。如何创建一个解决指定行记录的模态链接?

这是我到目前为止所做的。

查询:

<?php
    // Start MySQLi connection
    include '../../plugins/MySQL/connect_db.php';
    $db = new mysqli($dbhost,$dbuser,$dbpass,$dbname);

    if($db->connect_errno > 0){
        die('Unable to connect to database [' . $db->connect_error . ']');
    }

    // Build basic query
    $sql = ("SELECT CRS, ROOM, ARR, DEP, NTS, TITLE, FIRST, LAST, NAT, IHG_LVL, EMAIL FROM qci_poststay_ADMIN_temp");

    // run the query or show an error message
    if(!$result = $db->query($sql)){
        echo('There was an error running the query [' . $db->error . ']');
    }

    while($row = mysqli_fetch_array($result)){
        $crs = $row['CRS'];
        $room = $row['ROOM'];
        $arrival = $row['ARR'];
        $departure = $row['DEP'];
        $nights = $row['NTS'];
        $nationality = $row['NAT'];
        $title = $row['TITLE'];
        $first = $row['FIRST'];
        $last = $row['LAST'];
        $lvl = $row['IHG_LVL'];
        $email = $row['EMAIL'];

        echo "
            <tr>
                <td id=\"crs\">$crs</td>
                <td>$room</td>
                <td>$arrival</td>
                <td>$departure</td>
                <td>$nights</td>
                <td>$nationality</td>
                <td>$title</td>
                <td>$first</td>
                <td>$last</td>
                <td>$lvl</td>
                <td>$email</td>
                <td>00</td>
                <td>yyyy-mm-dd</td>
                <td>
                    <a id=\"Send_Mail\" class=\"btn btn-block btn-primary btn-xs\" target=\"_blank\" href=\"./sendmail.php?crs=$crs\" method=\"POST\">Send</a>

                    <button type=\"button\" class=\"btn btn-block btn-warning btn-xs\" data-toggle=\"modal\" data-target=\"#edit\">Edit</button>
                </td>
            </tr>";
    }

    //$result->free();
    $db->close();

?>

模态:

<!-- Modal -->
<div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Edit Details</h4>
      </div>
      <div class="modal-body">
        <table class="table">
            <tr>
                <?php
                echo "
                    <td>CRS No.: </td><td>$crs</td>";
                ?>
            </tr>
        </table>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>
<!-- /.Modal -->

非常感谢对此有所帮助。 谢谢!

0 个答案:

没有答案