2013-12-09 175 views
-2

我现在我以2这样的网页网址有很多条目的页面如何刷新页面而无需在PHP中重新加载?

http://localhost/DS/abc.php?id=1 

1-280-12/09/2013-ER-0-删除 2-280-12/09/2013-edr-0-delete ..... 所以当我删除它去页空白id和ofcourse该id被删除。我希望它应该重新加载或留在同一页上重新加载到相同的id.Here id =序列号,列1,2和280是零件号。我删除代码是

<?php 
     include_once('db.php'); 

    if(isset($_GET['del'])) 
     { 
$id = $_GET['del']; 
$sql= "DELETE FROM audi WHERE id='$id'"; 
$res= mysql_query($sql) or die("Failed".mysql_error()); 
echo "<meta http-equiv='refresh' content='0;url=abc.php?id='.$id.''>"; 

     } ?> 
+0

删除VIA Get请求是你能做的最糟糕的事!浏览页面的浏览器只会删除数据库。 – epascarello

+0

但它的工作正常4我除了abov.whats你的解决方案? – user3084297

+0

我不认为你可以像你问的那样去做你正在寻找的explicity服务器端。尝试使用JavaScript的Ajax请求。我也非常赞同@epascarello。 –

回答

0
<?php 
     include_once('db.php'); 

    if(isset($_GET['del'])) 
     { 
$id = $_GET['del']; 
$sql= "DELETE FROM audi WHERE id='$id'"; 
$res= mysql_query($sql) or die("Failed".mysql_error()); 

echo "<meta http-equiv='refresh' content='0;url=abc.php?id=".$id."'>"; // <- CORRECTION 

     } ?> 
+0

我treid,太........... – user3084297

+0

在删除页面上使用“echo $ id”或使用标题('location:abc。 php?id ='。$ id) – webzar

+0

@ user3084297在他的建议中我没有看到任何提及'echo'的内容。这是文字的PHP代码。 –

0

您可以使用AJAX来实现这一目标:

<html> 

<head> 
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script> 

    <script> 
     function deleteEntry(del) { 
      $.ajax({ 
       type: 'GET', 
       url: 'delete.php', 
       data: { del: del}, 
       success: function(response) { 
        alert('Entry Deleted') 
       } 
      }); 
     } 
    </script> 

</head> 

<body> 

    <button onclick="deleteEntry(5)">Delete Entry</button> 
    <!--5 is the del variable--> 

</body> 
</html> 

然后创建一个名为php文件“删除:

用JavaScript这样创建一个HTML页面.php“是这样的:

<?php 
    include_once('db.php'); 

    if(isset($_GET['del'])) 
    { 
     $id = $_GET['del']; 
     $sql= "DELETE FROM audi WHERE id='$id'"; 
     $res= mysql_query($sql) or die("Failed".mysql_error()); 
    } 
?> 

让我知道如果这个工程,欢呼!

物理“删除”按钮仅用于显示,您可以使用相同的原则不断重新加载php文件,同时传递删除ID。

+0

没有它不工作 – user3084297

+0

你得到什么错误? – Olokoo

相关问题