这是用于删除记录而不刷新页面的完整源代码。
以下步骤:
第一步:
DBConnect.php
class DBConnect
{
function DBConnect()
{
$link= mysql_connect("localhost","root","")or die("Local Host Error".mysql_error());
mysql_select_db("test");
}
function viewData()
{
$query = "SELECT * FROM test_mysql";
$resultset = mysql_query($query);
return $resultset;
}
function DeleteData($userID)
{
$query = "DELETE FROM test_mysql WHERE id=".$userID;
$resultset=mysql_query($query) ;
}
}
第二步:
delete.php
include_once'DBConnect.php';
if(isset($_REQUEST['userid']) && $_REQUEST['userid'])
{
$delObj= new DBConnect();
$delObj->DeleteData($_REQUEST['userid']);
}
第3步:
index.php
function deletedata(id)
{
var xmlhttp;
if (id=="")
{
document.getElementById("Display").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
window.location.reload()
}
}
xmlhttp.open("GET","delete.php?userid="+id,true);
xmlhttp.send();
}
include 'DBConnect.php';
$ViewObj= new DBConnect();
$ResultSet=$ViewObj->viewData();
?>
ID | Name | operation | Action |
---|
while($row= mysql_fetch_array($ResultSet))
{
?>
<?php echo $row[0];?><?php echo $row[1];?> Delete}
?>
,如果您觉得有任何问题,那么请让我know.hope它会帮助你。 谢谢。