level 2
狂是一种孤傲
楼主
1.conn
<?php
$conn=mysqli_connect("127.0.0.1","root","root","dbstudy")or die("数据库连接失败");
mysqli_query($conn, "SET NAMES UTF8");
?>
2.newslist
<?php
include_once("conn.php");
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>新闻列表以及分页</title>
<style type="text/css">
body {
font-family: "微软雅黑";
font-size: 14px;
margin: 10px;
}
</style>
</head>
<?php
$selectSQL = "SELECT * FROM `yu_news`,`yu_type` WHERE `yu_news`.`type_id` = `yu_type`.`type_id` ORDER BY `news_id` DESC LIMIT 0,53";
$record = mysqli_query($conn,$selectSQL);
?>
<body>
<form action="" method="post">
<table bgcolor="#CCCCCC" width="1200" border="0" align="center" cellpadding="6" cel
lsp
acing="1">
<thead>
<tr>
<td width="10%" height="24" align="right" bgcolor="#FFCC33">新闻编号</td>
<td width="40%" height="24" align="left" bgcolor="#FFCC33">新闻标题</td>
<td width="15%" height="24" align="center" bgcolor="#FFCC33">发布时间</td>
<td width="15%" height="24" align="center" bgcolor="#FFCC33">所属类别</td>
<td width="10%" height="24" align="right" bgcolor="#FFCC33">点击次数</td>
</tr>
</thead>
<tbody id="listBody">
<?php
$pageSize = 10;//定义变量$pageSize用来表示每页显示多少行
$rowCount = mysqli_num_rows($record); //定义变量$rowCount用来表示一共数据有多少行
$pageCount = ceil($rowCount/$pageSize);//定义变量$pageCount用来表示一共有多少页
if(isset($_GET["p"]))
{
$currentPage = $_GET["p"];//定义变量$currentPage用来表示当页面序(从1开始)
if($currentPage <= 1)
{
$currentPage = 1;
}
if($currentPage >= $pageCount)
{
$currentPage = $pageCount;
}
}
else
{
$currentPage = 1;
}
mysqli_data_seek($record,$pageSize*($currentPage-1));
$i = 0;
while($row = mysqli_fetch_array($record))
{
?>
<tr>
<td width="10%" height="24" align="right" bgcolor="#FFFFFF"><label><?=$row["news_id"]?><input type="checkbox" value="1000" name="ckbNewsIds[]" class="ckbNewsIds"></label></td>
<td width="40%" height="24" align="left" bgcolor="#FFFFFF"><?=$row["news_title"]?></td>
<td width="15%" height="24" align="center" bgcolor="#FFFFFF"><?=date("Y-m-d H:i:s",$row["news_addtime"])?></td>
<td width="15%" height="24" align="center" bgcolor="#FFFFFF"><?=$row["type_name"]?></td>
<td width="10%" height="24" align="right" bgcolor="#FFFFFF" ><?=$row["news_hit"]?></td>
</tr>
<?php
$i ++;
if($i == $pageSize)
{
break;
}
}
mysqli_free_result($record);
?>
</tbody>
<tfoot>
<tr>
<td width="10%" height="24" align="right" bgcolor="#FFFFFF"><label>全选/取消 <input type="checkbox" value="0" id="ckbCheckAll"></label></td>
<td colspan="4" height="24" bgcolor="#FFFFFF"><a href="?p=1">第一页</a> <a href="?p=<?=$currentPage-1?>">上一页</a> <a href="?p=<?=$currentPage+1?>">下一页</a> <a href="?p=<?=$pageCount?>">最后一页</a> 当前是第<?=$currentPage?>页/一共有<?=$pageCount?>页</td>
</tr>
</tfoot>
</table>
</form>
</body>
</html>
<?php
mysqli_close($conn);
?>
2021年06月17日 06点06分
1
<?php
$conn=mysqli_connect("127.0.0.1","root","root","dbstudy")or die("数据库连接失败");
mysqli_query($conn, "SET NAMES UTF8");
?>
2.newslist
<?php
include_once("conn.php");
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>新闻列表以及分页</title>
<style type="text/css">
body {
font-family: "微软雅黑";
font-size: 14px;
margin: 10px;
}
</style>
</head>
<?php
$selectSQL = "SELECT * FROM `yu_news`,`yu_type` WHERE `yu_news`.`type_id` = `yu_type`.`type_id` ORDER BY `news_id` DESC LIMIT 0,53";
$record = mysqli_query($conn,$selectSQL);
?>
<body>
<form action="" method="post">
<table bgcolor="#CCCCCC" width="1200" border="0" align="center" cellpadding="6" cel
lsp
acing="1">
<thead>
<tr>
<td width="10%" height="24" align="right" bgcolor="#FFCC33">新闻编号</td>
<td width="40%" height="24" align="left" bgcolor="#FFCC33">新闻标题</td>
<td width="15%" height="24" align="center" bgcolor="#FFCC33">发布时间</td>
<td width="15%" height="24" align="center" bgcolor="#FFCC33">所属类别</td>
<td width="10%" height="24" align="right" bgcolor="#FFCC33">点击次数</td>
</tr>
</thead>
<tbody id="listBody">
<?php
$pageSize = 10;//定义变量$pageSize用来表示每页显示多少行
$rowCount = mysqli_num_rows($record); //定义变量$rowCount用来表示一共数据有多少行
$pageCount = ceil($rowCount/$pageSize);//定义变量$pageCount用来表示一共有多少页
if(isset($_GET["p"]))
{
$currentPage = $_GET["p"];//定义变量$currentPage用来表示当页面序(从1开始)
if($currentPage <= 1)
{
$currentPage = 1;
}
if($currentPage >= $pageCount)
{
$currentPage = $pageCount;
}
}
else
{
$currentPage = 1;
}
mysqli_data_seek($record,$pageSize*($currentPage-1));
$i = 0;
while($row = mysqli_fetch_array($record))
{
?>
<tr>
<td width="10%" height="24" align="right" bgcolor="#FFFFFF"><label><?=$row["news_id"]?><input type="checkbox" value="1000" name="ckbNewsIds[]" class="ckbNewsIds"></label></td>
<td width="40%" height="24" align="left" bgcolor="#FFFFFF"><?=$row["news_title"]?></td>
<td width="15%" height="24" align="center" bgcolor="#FFFFFF"><?=date("Y-m-d H:i:s",$row["news_addtime"])?></td>
<td width="15%" height="24" align="center" bgcolor="#FFFFFF"><?=$row["type_name"]?></td>
<td width="10%" height="24" align="right" bgcolor="#FFFFFF" ><?=$row["news_hit"]?></td>
</tr>
<?php
$i ++;
if($i == $pageSize)
{
break;
}
}
mysqli_free_result($record);
?>
</tbody>
<tfoot>
<tr>
<td width="10%" height="24" align="right" bgcolor="#FFFFFF"><label>全选/取消 <input type="checkbox" value="0" id="ckbCheckAll"></label></td>
<td colspan="4" height="24" bgcolor="#FFFFFF"><a href="?p=1">第一页</a> <a href="?p=<?=$currentPage-1?>">上一页</a> <a href="?p=<?=$currentPage+1?>">下一页</a> <a href="?p=<?=$pageCount?>">最后一页</a> 当前是第<?=$currentPage?>页/一共有<?=$pageCount?>页</td>
</tr>
</tfoot>
</table>
</form>
</body>
</html>
<?php
mysqli_close($conn);
?>