dongzhangnong2063 2016-07-06 09:16
浏览 21

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

I am pulling records from a MySQL table and output them in a table on my webpage. Now I am in need of being able to edit the records which I tried to accomplish by placing an edit button at the end of each row, which is then supposed to open the record details in my bootstrap modal.

Sadly, this doesnt work as the passed on variables are all for the last entry of the queried records. How do I create a modal link that addresses the record of the specified row?

Here what I have so far.

Query:

<?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:

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

Much appreciate some help on this. Thanks!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题