如何将表格中选定的行ID赋予模型?

时间:2019-06-18 18:01:10

标签: php

好吧,我实际上不知道问题出在哪里,但是我的模态无法获取所选行的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 个答案:

答案 0 :(得分:0)

好的,现在我的一个朋友通过向我的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;

      }