将价值传递给模态

时间:2018-01-29 10:09:05

标签: php

我有这个数据表,我将获取每行的id并将其传递给模态,模态将显示id的更多详细信息。现在,当单击每一行时,模式将弹出并显示更多细节。我也将对编辑执行相同的操作,只在输入类型中使用值。

以下是表格的代码:

 <?php
echo ''.$row[0].'';
    $db = mysql_connect("localhost","root");  
    mysql_select_db("thesis");
    $sql = "SELECT * FROM childinfo Order by lastName ASC";
    $result = mysql_query($sql);

    if(mysql_num_rows($result)>0)
      {
        while($row = mysql_fetch_row($result)){
          if ($childID==$row[0]){

          echo '<div class="p-3 mb-2 bg-info text-white text-center rounded"><h6>Childs Basic Information</label></h6></div><br>';
          echo '<b>Full Name: </b>'.$row[1].', ' .$row[2]. ' '.$row[3].'<br>';
          echo '<b>Gender: </b>'.$row[11].'<br>';
          echo '<b>Birthday: </b>'.$row[5].'<br>';
          echo '<b>Age: </b>'.$row[6].'<br>';
          echo '<b>Name of Main Household: </b>'.$childID.'<br><br>';
          echo '<div class="p-3 mb-2 bg-info text-white text-center rounded"><h6>Childs Health Information</label></h6></div><br>';
          echo '<b>Height: </b> <input type="text" name="height" class="form-control" value="'.$row[8].'">';
          echo '<b>Weight: </b><input type="text" name="weight" class="form-control" value="'.$row[7].'">';
          echo '<b>BMI: </b><input type="text" name="bmi" class="form-control" value="'.$row[9].'">';
           echo '<b>Date Weighed: </b><input type="date" name="dateWeighed" class="form-control" value="'.$row[13].'">';
          echo '<b>Health History: </b><input type="text" name="healthHis" class="form-control" value="'.$row[12].'">';


      }}}
?>

以下是我的模态的代码:

<div class="modal fade" id="view" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLongTitle">Child Profile</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">


<?php
echo ''.$childID.'';
    $db = mysql_connect("localhost","root");  
    mysql_select_db("thesis");
    $sql = "SELECT * FROM childinfo Order by lastName ASC";
    $result = mysql_query($sql);

    if(mysql_num_rows($result)>0)
      {
        while($row = mysql_fetch_row($result)){

          if ($childID==$row[0]){
          echo '<div class="p-3 mb-2 bg-info text-white text-center rounded"><h6>Childs Basic Information</label></h6></div><br>';
          echo '<b>Full Name: </b>'.$row[1].', ' .$row[2]. ' '.$row[3].'<br>';
          echo '<b>Gender: </b>'.$row[11].'<br>';
          echo '<b>Birthday: </b>'.$row[5].'<br>';
          echo '<b>Age: </b>'.$row[6].'<br>';
          echo '<b>Name of Main Household: </b>'.$childID.'<br><br>';
          echo '<div class="p-3 mb-2 bg-info text-white text-center rounded"><h6>Childs Health Information</label></h6></div><br>';
          echo '<b>Height: </b>'.$row[8].' cm <br>';
          echo '<b>Weight: </b>'.$childID.' kg <br>';
          echo '<b>BMI: </b>'.$row[9].'<br>';
           echo '<b>Date Weighed: </b>'.$row[13].'<br>';
          echo '<b>Health History: </b>'.$row[12].'<br>';
  echo '<b>Health Status: </b>'.$row[10].'<br>';

      }}}
?>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

现在,它只会回显表中最后一个id而只回显那个id。

0 个答案:

没有答案