2016-05-03 31 views
0

我正在使用PHP管理面板,在那里我想以HTML表格的形式显示用户列表。在每个表格行中都有一个按钮,管理员可以将通知发送给选定的用户。点击按钮在PHP中的ID

我从下面的代码创建的表,并预期:

<div class="table"> 
<div style="overflow: auto;height: 400px; width: 100%;"> 
<form method='post'> 
<table width="100%" border="0" cellspacing="0" cellpadding="0"> 
    <tr> 
     <th>Id</th> 
     <th>Package</th> 
     <th>Date</th> 
     <th>Referring Agent</th> 
     <th>Content Control</th> 
    </tr> 
    <?php if(!empty($records)){ 
      foreach($records as $k=>$v){ 
      ?> 
      <tr> 
      <td><?php echo $v['id']; ?></td> 
      <td><h3><a href="#"><?php echo $v['firstname']; ?></a></h3></td> 
      <td><?php echo $v['lastname']; ?></td> 
      <td><?php echo $v['email']; ?></td> 
      <!--<td><input id='<?php echo $v['id']; ?>' type='submit' name ='send_notification' value='Send Notification'></td>--> 
      <td> 
      <div class="pagging"> 
      <a href="#" onclick="sendNotification('<?php echo $v['id'];?>')">Send Notification</a> 
      </div> 
      </td> 
      </tr> 
      <?php 
    } 
}else{ 
    ?> 
     <tr> 
     <td colspan="5" align='center'><?php echo "No record added yet"; ?> 
     </tr> 
    <?php 
} 
?> 

我想将每行的“身份证”发送到一些功能上的“发送通知”在那里我可以进行点击显示PHP中的数据库操作。我无法做到这一点。我想点击'发送通知'在PHP中的函数将执行哪些将执行一些数据库操作。

+1

其中是您的函数sendNotification()。你的html代码是正确的。使用AJAX你可以实现它。 – RJParikh

+0

您需要在此函数上使用ajax,并在ajax url页面上执行数据库操作。 – RJParikh

回答

1

您需要使用AJAX。使用下面的代码。

Ajax代码

<script> 
    function sendNotification(id) 
    { 
     $.ajax({ 
      type: "POST", 
      url: "update.php", 
      data: {id:id}, 
      success: function(html) { 
       alert("Updated successfully"); 
      } 
     }); 
    } 
</script> 

PHP代码:update.php

<?php 
if(isset($_POST['id'])) 
{ 
    //Update query and operation here 
} 
?> 

下载最新的jQuery需要从这里。 Click Here

+0

这是jQuery lib的一个古老版本。我不会在你的答案中宣传这一点。目前在[v2.2.3](https://jquery.com/download/) – Marcus

+0

是的,我已经添加了链接从那里下载jquery。 @马库斯 – RJParikh