2016-05-14 106 views
0

我想显示数据多选择复选框,并显示模式引导数据库中的数据?如何获取数据多复选框jquery show modal bootstrap

指数(PHP)

JavaScript代码

<script type="text/javascript"> 
$(document).ready(function() 
{ 
    $("#btnDetail").click(function() 
    { 
     $('#modalForm').modal('show').on('shown.bs.modal',function() 
     { 
      var data = $("#data").val(); 
      $.post('page/user/detail_user.php', 
      { 
       id_data:$(this).attr(data) 
      }, 
      function() 
      { 
       $('.modal-body').html(data); 
      }); 
     });  
    }); 
}); 
</script> 

数据用户

<table width="100%" border="1"> 
    <tbody> 
     <tr> 
      <td width="3%" align="center">&nbsp;</td> 
      <td width="97%" align="center">NAME</td> 
     </tr> 
     <?php 
     $qry = mysql_query("SELECT * FROM t_users"); 
     while($data = mysql_fetch_array($qry)) 
     { 
     ?> 
      <tr> 
       <td align="center"><input type="checkbox" name="data[]" id="data[]" value='<?php echo $data['id']?>'></td> 
       <td><?php echo $data['name']?></td> 
      </tr> 
     <?php 
     } 
     ?> 
    </tbody> 
</table> 
<button id='btnDetail' name='btnDetail'>Detail User</button> 

模态

<div class="modal fade" id="modalForm" name='modalForm' tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
    <div class="modal-dialog"> 
     <div class="modal-content"> 
      <div class="modal-header"> 
       <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button> 
       <h4 class="modal-title blue" id="myModalLabel"></h4> 
      </div> 
      <div class="modal-body"> 
      </div> 
      <div class="modal-footer"> 
      </div> 
     </div> 
    </div> 
</div> 

详细信息用户(PHP)

<?php 
$id = $_POST['id_data']; 

$qry = mysql_query("SELECT * FROM t_users WHERE id='$id'"); 
while($data = mysql_fetch_array($qry)) 
{ 
?> 
<table width="100%" border="1"> 
    <tbody> 
    <tr> 
     <th colspan='3'> 
      Detail Data Users 
     </th> 
    </tr> 
    <tr> 
     <td>ID</td> 
     <td>NAME</td> 
     <td>STATUS</td> 
    </tr> 
    <tr> 
     <td><?php echo $data['id']?></td> 
     <td><?php echo $data['name']?></td> 
     <td><?php echo $data['status']?></td> 
    </tr> 
    </tbody> 
</table> 

<?php 
} 
?> 

场景:
当按钮详细信息用户在点击运行jQuery和值复选框,然后发送到模态引导,然后从jQuery的运行代码的PHP发布到显示模态引导数据库中的结果数据。

+0

你能否简单地总结一下,说明什么可行,哪些不行。我很想知道你想要什么,但为了帮助别人的人,最好有(如果可能的话)明确的问题。 –

+0

感谢您的帮助,我的问题是如何在数据库中显示数据到模态引导选中的复选框?,谢谢 –

回答

0

这里有提示来解决这个问题:在HTML

  1. ID必须是唯一的。 (不作为所有复选框的ID“数据[]”)
  2. this是上下文相关的。所以,当你在引导函数中使用this时,它可能(我必须确保)并不意味着以前的jQuery函数。
  3. 您应该管理检索所有选中框的值。
  4. PHP代码应该使用IN运算符来代替ID。
+0

那么我应该从哪里开始编码修复呢? –

+0

开始纠正我指出的。我现在必须睡在这里,深夜。尝试使用当前代码查找每个点。在询问之前尝试一些东西,并告诉我你尝试了什么。 –

+0

okey,祝你有个美好的一天 –

相关问题