dswe30290 2018-05-07 05:46
浏览 21

Php,Mysql无法检索每一行的列数据

I'm trying to give each modal form a unique id based on results retrieved from my database so that different data will be passed onto the php form processor. I have 1 table that is placed in a form which has the unique value for each row being "mapid"

However, each row also has a modal which I've placed another form in but the only value I'm getting is the first row of the sql query. Please help.

    $sql = "SELECT mapid, location, DATE_FORMAT(date,'%d/%m/%y') AS date, status FROM maps ORDER BY status DESC, date DESC ";    
$result = $mysqli->query($sql);


if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {

echo
'
<form action="map.php" method="post">

    <tr>

        <td> '. $row["mapid"].' </td>

        <td> '. $row["location"].' </td>

        <td> ' . ($row["status"]=='0' ? 'Last Done' : (($row["status"]=='1') ? 'Started' : 'Done')).' </td>

        <td> '.$row["date"].' </td>

        <td> ' . 
        (($row["status"]=='0') ?
            '<input type="hidden" name="mapid" value="'. $row["mapid"].'"/>
            <input type="hidden" name="start" value="start"/>
                <button class="btn btn-primary" name="getmap" type="submit">Start</button>'

        : (($row["status"]=='1') ? 
            '<input type="hidden" name="mapid" value="'. $row["mapid"].'"/>
            <input type="hidden" name="resume" value="resume"/>
            <button class="btn btn-danger" type="submit" name="getmap" value="'. $row["mapid"].'">Resume</button>'

        : (($row["status"]=='2') ?
           '<input type="hidden" name="mapid" value="'. $row["mapid"].'"/>
            <input type="hidden" name="process" value="process"/>
                <button class="btn btn-primary" type="submit" name="getmap">Process</button>' 
        : ''))) . '

        </td>
</form>


        <td>
            <button class="btn btn-primary" data-toggle="modal" data-target="#assign['. $row["mapid"].']">Assign</button>
        </td>

        <div class="modal fade" id="assign['. $row["mapid"].']" tabindex="-1" role="dialog" aria-labelledby="assignLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <form action="work/allocate.php" method="post">

                <div class="modal-header">
                    <h5 class="modal-title" id="assignLabel">Assign Map</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>

                <div class="modal-body">
                    <input type="hidden" name="mapid">
                    <p> Assign <strong>Map '. $row["mapid"].' - '. $row["location"].' </strong> to:</p>
                    <input class="form-control" id="name" name="name" type="text" >
                </div>

                <div class="modal-footer">
                    <button class="btn btn-primary" name="assigned" id="assigned" type="submit">Assign</button>
                </div>

               </form>

    </tr>


            </div>
        </div>
    </div>

    '
  • 写回答

1条回答 默认 最新

  • dphw5101 2018-05-07 06:56
    关注

    Just needed to give the modal a unique id by adding ['. $row["mapid"].'] next to #assign.

     <td>
                <button class="btn btn-primary" data-toggle="modal" data-target="#assign['. $row["mapid"].']" value"">Assign</button>
            </td>
            
            
            
            <div class="modal fade" id="assign['. $row["mapid"].']" tabindex="-1" role="dialog" aria-labelledby="assignLabel" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作