为了账号安全,请及时绑定邮箱和手机立即绑定

如何将表中选定的行 ID 提供给我的模型?

如何将表中选定的行 ID 提供给我的模型?

PHP
HUX布斯 2021-08-28 10:10:33
好吧,我实际上不知道问题出在哪里,但是我的模态没有获得我选择的行的 ID。我的模态需要获取所选行的描述。因此,如果您在我的表中选择第 2 行,您需要在我的数据库中获取 ID 2 的描述。<tr data-toggle='modal' value=".$row["ID"]." data-target='#myModal' id=".$row["ID"].">                                     <td>" . $row["ID"]. "</td>                                     <td>" . $row["Name"]. " </td>                                     <td>" . $row["Category"]. " </td>                                     <td>" . $row["Skill"]. " </td>                                     <td>" . $row["CareerCompetence"]. " </td>                                     <td>" . $row["DateAdded"]. " </td>                                     <td>" . $row["EmailUploader"]. " </td>                                      <td> ";                                     ?>                           <div class="modal fade" id="myModal" role="dialog">                             <div class="modal-dialog">                               <!-- Modal content-->                               <div class="modal-content">                                 <div class="modal-header">                                   <?php                                   $sql2 = "SELECT * FROM class where ID='".$row['ID']."'";                                   $result2 = $con->query($sql2);                                   while($row2 = $result2->fetch_assoc()) {                                     ?>                                   <h4 class="modal-title"><?php echo $row2["Name"]; ?></h4>                                 </div>                                 <div class="modal-body">                                   <p><?php echo $row2['Descriptie'];?></p>                                   <p><?php echo $row2['FileName'];?></p>                                 </div>                                 <div class="modal-footer">                                   <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>                                 </div>                               </div>
查看完整描述

1 回答

?
至尊宝的传说

TA贡献1789条经验 获得超10个赞

好的,现在我的一个朋友通过在我的 tr 中添加一键解决了这个问题。如果你现在点击表格中的一行,你会看到一个带有该行描述的弹出窗口。下表代码:


// Head of the table

<thead>

    <tr>

   <th>ID</th>

   <th>Name</th>

   <th>category</th>

   <th>Skills</th>

   <th>competenties</th>

   <th>date added</th>

   <th>Email uploader</th>

   <th>Visable</th>

   <th>Approve</th>

   <th>Disapprove</th>

</tr>

</thead>




// Data of the table 


$data = "<p>".$row['Descriptie']."</p>"; //data is the Description of the row you send it to your modal by using \"OpenModalWith('$data')"

 <tr onclick=\"OpenModalWith('$data', '".$row["Name"]."');\" data-toggle='modal' value=".$row["ID"]." data-target='#myModal' id=".$row["ID"].">

 <td>" . $row["ID"]. "</td>

                                      <td>" . $row["Name"]. " </td>

                                      <td>" . $row["Category"]. " </td>

                                      <td>" . $Skill. " </td>

                                      <td>" . $Competences. " </td>

                                      <td>" . $row["DateAdded"]. " </td>

                                      <td>" . $row["EmailUploader"]. " </td> 

                                      <td> ";

这是模态( row['description'] 是该行的描述):


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

                              <div class="modal-dialog">


                                <!-- Modal content-->

                                <div class="modal-content">

                                  <div class="modal-header">


                                    <h4 class="modal-title"></h4>

                                  </div>

                                  <div class="modal-body">

                                    <p><?php echo $row2['Descriptie'];?></p>


                                  </div>

                                  <div class="modal-footer">

                                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>

                                  </div>

                                </div>


                              </div>

                            </div>


在我的 javascript 代码中,他说获取 elementbyID 因此,例如 myModal(myModal 是我的模态 ID)


function OpenModalWith(content, title){

          modal = document.getElementById("myModal");

          modaltitle = modal.getElementsByClassName("modal-title")[0];

          modalbody = modal.getElementsByClassName("modal-body")[0];

          modalbody.innerHTML = content;

          modaltitle.innerHTML = title;


      }


查看完整回答
反对 回复 2021-08-28
  • 1 回答
  • 0 关注
  • 115 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信