<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head >
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<style type="text/css">
#apDiv1 {
position: absolute;
width: 346px;
height: 44px;
z-index: 1;
left: 485px;
top: 63px;
font-size: 36px;
}
</style>
</head>
<body>
<form >
<?php
include_once "conn.php";
//获得get请求的数据后,执行删除操作
$news_id=isset($_REQUEST["NewID"])?$_REQUEST["NewID"]:false;
$strDel=" delete from car.News where news_id='$news_id' ";
if($news_id)
mysqli_query($conn,$strDel);
if(mysqli_affected_rows($conn)>0)
{
echo "<script>alert('删除成功,点击返回原页面')</script>";
}
//分页显示
$pagesize=6; //设置每页显示6个记录
$url=$_SERVER["REQUEST_URI"];
$url=parse_url($url);
$url=$url["path"];
$strQuery=" select * from car.News order by time desc";
$result=mysqli_query($conn,$strQuery);
$num=mysqli_num_rows($result);
if($_SERVER["REQUEST_METHOD"]=="GET")
{
$pageval=isset($_GET["page"])?$_GET["page"]:false;
$page=($pageval-1)*$pagesize;
$page.=',';
}
if($num>$pagesize)
{
if($pageval<=1) $pageval=1;
echo "共$num 条"."<a href=$url?page=1>首页</a>".
($pageval>1?("<a href=$url?page=".($pageval-1).">上一页</a>"):"上一页").
($pageval<ceil($num/$pagesize)?("<a href=$url?page=".($pageval+1).">下一页</a>"):"下一页").
"<a href=$url?page=".ceil($num/$pagesize).">末页</a>";
}
else
echo "共$num 条,仅此页";
$sql=" select * from car.News order by time desc limit $page $pagesize";
$result_sql=mysqli_query($conn,$sql);
?>
<div>
<table width="100%" border="3" bordercolor="#00FFFF">
<tr>
<td width="22%" height="49" align="center" style="font-size: 24px">新闻添加时间</td>
<td width="65%" align="center">新闻标题</td>
<td width="13%" align="center">操作</td>
</tr>
<?php
if(!empty($result_sql))
while($row=mysqli_fetch_array($result_sql))
{
?>
<tr>
<td height="42" align="center"><?php echo $row["time"] ?></td>
<td align="center"><?php echo $row["title"] ?></td>
<td align="center"><a href="DelNews.php?NewID=<?php echo $row["news_id"]?>">删除</a>
</td>
</tr>
<?php
}
?>
</table>
</div>
</form>
<div id="apDiv1" align="center">后台新闻删除界面</div>
</body>
</html>
里面有个小bug,不过不影响主体功能。