编辑php内部循环的特定记录


Edit specific record that inside php looped

现在我已经写出来了

<div class="row">
 <div class="col-lg-12">
  <table id="usertable" class="table table-bordered table-hover text-center">
   <thead>
    <th class="col-lg-1 text-center">User ID</th>
    <th class="col-lg-4 text-center">Username</th>
    <th class="col-lg-4 text-center">Password</th>
    <th class="col-lg-2 text-center">Role</th>
   </thead>
   <tbody>
   <?php
    require('dbconnectmssql.php');
    $sql = "select [User_ID],[user_decoded],[pass_decoded],[permission] from [rfttest].[dbo].[users]";
    $query = sqlsrv_query ($conn , $sql);
    if($query === false)
    {die( print_r( sqlsrv_errors(), true));}
    while($row = sqlsrv_fetch_array( $query, SQLSRV_FETCH_NUMERIC))
    {
     echo "<tr>";
     foreach($row as $x => $a)
     {
      echo "<td>".$a."</td>";
     }
      echo "<td>";
      echo "<a href='#' ><span class='glyphicon glyphicon-wrench' aria-hidden='true'></span></a>";
      echo "<a href='usercontrol.php?del=$row[0]'>";
      echo "<span class='glyphicon glyphicon-trash' aria-hidden='true'></span>";
      echo "</a>";
      echo "</td>";
      echo "</tr>";
     }
     ?>
    </tbody>
   /table>
  </div>
 </div>

是关于查询输出和显示表中有多少用户。

  • 我已经通过链接到PHP文件和$_GET数据完成了删除记录(如果有您建议的另一种解决方案,可能稍后会改进)

我想做的另一件事是

  • 编辑特定的记录而不重定向到另一个页面

我现在的想法是隐藏表单在点击编辑后弹出例如我点击了然后表单弹出数据记录,用户可以编辑它并通过提交到PHP文件保存它然后重定向到这个页面

类似:在引导弹出窗口中包含表单?邮报》

<a href="#" id="popover">the popover link</a>
<div id="popover-head" class="hide">
  some title
</div>
<div id="popover-content" class="hide">
  <!-- MyForm -->
</div>

但我还是想不明白

  • 我怎么能编码出来,使链接打开特定的popover-head/内容也许popover-head/内容必须包含在id或什么?
  • PHP呢
  • JS/JQ也

任何解决方案,我只想要一些东西编辑特定的记录,回声

对不起,我的英语不好

谢谢

您可能希望使用AJAX。

这对我来说看起来很痛苦-如果它起作用,谷歌蜘蛛会删除页面上的所有用户:

}
  echo "<td>";
  echo "<a href='#' ><span class='glyphicon glyphicon-wrench' aria-hidden='true'></span></a>";
  echo "<a href='usercontrol.php?del=$row[0]'>";
  echo "<span class='glyphicon glyphicon-trash' aria-hidden='true'></span>";
  echo "</a>";
  echo "</td>";
  echo "</tr>";
 }

可以写成

} ?>
 <td>
 <a href='#' ><span class='glyphicon glyphicon-wrench' aria-hidden='true'></span></a>
 <a class="del" href='#' data-userid='<?PHP echo row["User_ID"]; ?>'>
 <span class='glyphicon glyphicon-trash' aria-hidden='true'></span>
 </a>
</td>
</tr>
<?PHP } ?>

然后

$(function() {
  $(".del").on("click",function(e) {
    e.preventDefault(); stop the page from reloading
    var id=$(this).data("userid");
    $.get("usercontrol.php?del="+id,function() {
      alert(id + "deleted");
    });
  });
});

编辑
  • 使用.show().hide()弹出一个表单
  • 更改数据
  • AJAX提交更改-确保使用preventDefault to停止实际提交$("form").on("submit",function(e) { e.preventDefault(); $.post("save.php",$(this).serialize(),function(data) { alert("saved"); $("#formDiv").hide() });});
  • 显示结果
  • 关闭弹出窗口