首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编辑php内循环的特定记录

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

Stack Overflow用户
提问于 2015-08-25 07:32:10
回答 1查看 59关注 0票数 0

现在我已经把它写出来了

代码语言:javascript
复制
<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数据的delete-record链接(如果有另一种解决方案,您可能会建议以后改进)。

我想做的另一件事是

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

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

类似于:Contain form within a bootstrap popover?帖子

代码语言:javascript
复制
<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/内容--可能popover/内容必须包含在id或其他内容中?
  • PHP呢?
  • 那JS/JQ呢?

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

抱歉,我的英语不好

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-25 07:43:52

您可能希望为此使用AJAX。

这在我看来太痛苦了--如果它奏效了,谷歌就会删除页面上的所有用户:

代码语言:javascript
复制
}
  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>";
 }

它可以写成

代码语言:javascript
复制
} ?>
 <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 } ?>

然后

代码语言:javascript
复制
$(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停止实际提交$("form").on("submit",function(e) { e.preventDefault(); $.post("save.php",$(this).serialize(),function(data) { alert("saved"); $("#formDiv").hide() });});
  • 显示结果
  • 关闭弹出窗口
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32198028

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档