获取正确的ID值并填充到模态弹出窗口

时间:2015-05-29 03:48:33

标签: php mysql

https://www.dropbox.com/s/e89hjxrogghll9a/1.jpg?dl=0 https://www.dropbox.com/s/sjqfsuwj9mlpc2o/2.jpg?dl=0 请参阅上面的图片链接。图像显示过程

如果我单击我选择的表,则无法选择正确的数据。这是我的代码。感谢您的帮助



 <table id="example2" class="table table-bordered table-hover">
                    <thead>
                      <tr>
                        <th>Code</th>
                        <th>Date of Request</th>
                        <th>Requestor Name</th>
                        <th>Form Type</th>
                        <th>Request Type</th>
                         <th>Details</th>
                         <th>Date Needed</th>
                         
                        <th>Action</th>
                         
                      </tr>
                    </thead>
             
                <?php
             
                    $req1 = mysql_query('select * from mainviewrequestor where username="'.$_SESSION['username'].'"  and req_dateapprove IS NULL');
                    
while($dn1 = mysql_fetch_array($req1))
{
?>
<tr>
       <td><?php echo date($dn1['req_code']); ?></td>  
       <td><?php echo date($dn1['req_date']); ?></td>
      <td class="left"><a href="read_pm.php?id=<?php echo $dn1['id']; ?>"><?php echo htmlentities($dn1['empname'], ENT_QUOTES, 'UTF-8'); ?></a></td>
      
      <td><?php echo htmlentities($dn1['form_name'], ENT_QUOTES, 'UTF-8'); ?></td>
      <td> <?php echo $dn1['itrf_type']?></td>
      <td> <?php echo $dn1['itrf_details']?></td>
      <td> <?php echo $dn1['req_dateneeded']?></td>
       <td class="left"><a href="#proceed" data-toggle="modal"><button type="submit" class="btn btn-primary" name="approved">View</button></a>
        <button type="submit" class="btn btn-primary" name="btn-sub2">DisApproved</button></td>
      
    </tr>
   
     
    <?php
}

if(intval(mysql_num_rows($req1))==0)
{
?>
  <tr>
      <td colspan="4" class="center">You have no unread message.</td>
    </tr>
<?php
}
?>
</table>
<br />

<?php
}
?>
           
                     
                  </table>
                </div><!-- /.box-body -->
              </div><!-- /.box -->

              
                   
            </div><!-- /.col -->
          </div><!-- /.row -->
        </section><!-- /.content -->
      </div><!-- /.content-wrapper -->

     <?php
       
     
                     

                $req1 = mysql_query('select * from mainviewrequestor2');
while($dn1 = mysql_fetch_array($req1))                        

{

                 ?>


<!--Pop-up modal Code-->

<div class = "modal fade" id="proceed" role="dialog">
  <div class = "modal-dialog modal-lg">
       <div class = "modal-content">
          <div class = "modal-header">
              <h4>REQUEST TABLES</h4>
                <h2>------------------------------------------------------------------------------------------</h2>
               
                 
              <div class="content">  
                <form>  
                   <label>Date Created: </label><input type="text" name="req_date" id="req_date" value="<?php echo ($dn1['req_date']); ?>" /><br />
                   <label>Request By: </label><input type="text" name="empname" id="empname" value="<?php echo ($dn1['empname']) ?>" /><br />
                   <label>Form Name: </label><input type="text" name="form_name" id="form_name" value="<?php echo $dn1['form_name']?>" /><br />
                   <label>Request Type: </label><input type="text" name="itrf_type" id="itrf_type" value="<?php echo $dn1['itrf_type']?>" /><br />
                   <label>Details: </label><input type="text" name="itrf_details" id="itrf_details" value="<?php echo $dn1['itrf_details']?>" /><br />
                    <label> Date Needed:</label><input type="text" name="req_dateneeded" id="req_dateneeded" value="<?php echo $dn1['req_dateneeded']?>" /><br />
                  
                  <button type="submit" class="btn btn-primary" name="req_code">Approved</button>
                  <button type="submit" class="btn btn-primary" name="update2">Disapproved</button>
                 
                 </form> 
                </div>

 <?php
}


?>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

你需要替换每个模态元素上的#proceed id和h ref元素,以便它们对应

为你的表

<a href="#proceed-<?php echo $req1['id'];?>" data-toggle="modal">

对于你的模态

while($dn1 = mysql_fetch_array($req1))                        

{?>
<div class = "modal fade" id="proceed-<?php echo $dn1['id'];?>" role="dialog">

虽然这是一种选择做事的相当丑陋的方式。 我只会创建一个模态,并将ID传递给ajax函数以加载所述表单。但那就是我,这就是另一个话题。

但这可以解决你的问题。