物联网phpXINWEN
php吧
全部回复
仅看楼主
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
level 1
<?php
include_once("conn.php");
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<ul><?php
$selectSQLforNews = "SELECT * FROM `yu_type` ORDER BY `type_id`=1 DESC ";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
$rowforNews = mysqli_fetch_array($recodeforNews);
?>
<li><h4> <?php $str="一二三四";echo substr($str,0,3);?>、<?=$rowforNews["type_name"]?></h4><>
<li>
<ul><?php
$selectSQLforNews = "SELECT * FROM `yu_news` WHERE `type_id`=1 ORDER BY `news_hit`DESC LIMIT 0,5";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
while ($rowforNews = mysqli_fetch_array($recodeforNews))
{
?>
<li>·<?=$rowforNews["news_title"]?>[<?=$rowforNews["news_hit"]?>]<>
<?php
}
mysqli_free_result($recodeforNews);
?>
</ul>
</li>
<?php
$selectSQLforNews = "SELECT * FROM `yu_type` ORDER BY `type_id`=2 DESC ";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
$rowforNews = mysqli_fetch_array($recodeforNews);
?>
<li><h4> <?php $str="一二三四";echo substr($str,3,3);?>、<?=$rowforNews["type_name"]?></h4> </li>
<li>
<ul>
<?php
$selectSQLforNews = "SELECT * FROM `yu_news` WHERE `type_id`=2 ORDER BY `news_hit` DESC LIMIT 0,5";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
while ($rowforNews = mysqli_fetch_array($recodeforNews))
{
?>
<li>· <?=$rowforNews["news_title"]?>[<?=$rowforNews["news_hit"]?>] </li>
<?php
}
mysqli_free_result($recodeforNews);
?>
</ul>
</li>
<?php
$selectSQLforNews = "SELECT * FROM `yu_type` ORDER BY `type_id`=3 DESC ";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
$rowforNws = mysqli_fetch_array($recodeforNews);
?>
<li><h4><?php $str="一二三四";echo substr($str,6,3);?>、<?=$rowforNews["type_name"]?></h4> </li>
<li>
<ul>
<?php
$selectSQLforNews = "SELECT * FROM `yu_news` WHERE `type_id`=3 ORDER BY `news_hit` DESC LIMIT 0,5";
$recodeforews = mysqli_query($conn,$selectSQLforNews);
while ($rowforNews = mysqli_fetch_array($recodeforNews))
{
?>
<li><?=$rowforNews["news_title"]?>[<?=$rowforNews["news_hit"]?>] </li>
<?php
}
mysqli_free_result($recodforews);
?>
</ul>
</li>
<?php
$selectSQLforNews = "SELECT * FROM `yu_type` ORDER BY `type_id`=4 DESC ";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
$rowforNews = mysqli_fetch_array($recodeforNews);
?>
<li><h4><?php $str="一二三四";echo substr($str,9,3);?>、<?=$rowforNews["type_name"]?></h4> </li>
<li>
<ul><?php
$selectSQLforNews = "SELECT * FROM `yu_news` WHERE `type_id`=4 ORDER BY `news_hit` DESC LIMIT 0,5";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
while ($rowforNews = mysqli_fetch_array($recodeforNews))
{
?>
<li>·<?=$rowforNews["news_itle"]?>[<?=$rowforNews["news_hit"]?>] </li>
<?php
}
mysqli_free_result($recodeforNews);
?>
</ul>
</li>
</ul>
<?php
mysqli_close($conn);
?>
</body>
</html>
2021年06月18日 01点06分 2
level 1
<?php
$conn=mysqli_connect("127.0.0.1","root","root","dbstudy")or die("数据库连接失败");
mysqli_query($conn, "SET NAMES UTF8");
?>
2021年06月18日 01点06分 3
level 2
conn.php
<?php
$conn = mysqli_connect("127.0.0.1","root","root","dbstudy") or die("数据库连接失败!");
mysqli_query($conn,"SET NAMES UTF8");
?>
news.php
<?php
include_once("conn.php");
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<ul><?php
$selectSQLforNews = "SELECT * FROM `yu_type` ORDER BY `type_id`=1 DESC ";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
$rowforNews = mysqli_fetch_array($recodeforNews);
?>
<li><h4> <?php $str="一二三四";echo substr($str,0,3);?>、<?=$rowforNews["type_name"]?></h4><>
<li>
<ul><?php
$selectSQLforNews = "SELECT * FROM `yu_news` WHERE `type_id`=1 ORDER BY `news_hit`DESC LIMIT 0,5";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
while ($rowforNews = mysqli_fetch_array($recodeforNews))
{
?>
<li>·<?=$rowforNews["news_title"]?>[<?=$rowforNews["news_hit"]?>]<>
<?php
}
mysqli_free_result($recodeforNews);
?>
</ul>
</li>
<?php
$selectSQLforNews = "SELECT * FROM `yu_type` ORDER BY `type_id`=2 DESC ";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
$rowforNews = mysqli_fetch_array($recodeforNews);
?>
<li><h4> <?php $str="一二三四";echo substr($str,3,3);?>、<?=$rowforNews["type_name"]?></h4> </li>
<li>
<ul>
<?php
$selectSQLforNews = "SELECT * FROM `yu_news` WHERE `type_id`=2 ORDER BY `news_hit` DESC LIMIT 0,5";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
while ($rowforNews = mysqli_fetch_array($recodeforNews))
{
?>
<li>· <?=$rowforNews["news_title"]?>[<?=$rowforNews["news_hit"]?>] </li>
<?php
}
mysqli_free_result($recodeforNews);
?>
</ul>
</li>
<?php
$selectSQLforNews = "SELECT * FROM `yu_type` ORDER BY `type_id`=3 DESC ";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
$rowforNws = mysqli_fetch_array($recodeforNews);
?>
<li><h4><?php $str="一二三四";echo substr($str,6,3);?>、<?=$rowforNews["type_name"]?></h4> </li>
<li>
<ul>
<?php
$selectSQLforNews = "SELECT * FROM `yu_news` WHERE `type_id`=3 ORDER BY `news_hit` DESC LIMIT 0,5";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
while ($rowforNews = mysqli_fetch_array($recodeforNews))
{
?>
<li>· <?=$rowforNews["news_title"]?>[<?=$rowforNews["news_hit"]?>] </li>
<?php
}
mysqli_free_result($recodeforNews);
?>
</ul>
</li>
<?php
$selectSQLforNews = "SELECT * FROM `yu_type` ORDER BY `type_id`=4 DESC ";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
$rowforNews = mysqli_fetch_array($recodeforNews);
?>
<li><h4><?php $str="一二三四";echo substr($str,9,3);?>、<?=$rowforNews["type_name"]?></h4> </li>
<li>
<ul><?php
$selectSQLforNews = "SELECT * FROM `yu_news` WHERE `type_id`=4 ORDER BY `news_hit` DESC LIMIT 0,5";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
while ($rowforNews = mysqli_fetch_array($recodeforNews))
{
?>
<li>·<?=$rowforNews["news_title"]?>[<?=$rowforNews["news_hit"]?>] </li>
<?php
}
mysqli_free_result($recodeforNews);
?>
</ul>
</li>
</ul>
<?php
mysqli_close($conn);
?>
</body>
</html>
2021年06月18日 02点06分 4
level 2
<?php
$conn = mysqli_connect("127.0.0.1","root","root","dbstudy") or die("数据库连接失败!");
mysqli_query($conn,"SET NAMES UTF8");
?>
<?php
include_once("conn.php");
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<style type="text/css">
body,td,th {
font-size: 14px;
line-height: 23px;
font-family: "微软雅黑";
margin: 10px;
}
ul {
list-style: none;
padding-left: 2em;
}
</style>
<body>
<ul><?php
$selectSQLforNews = "SELECT * FROM `yu_type` ORDER BY `type_id`=1 DESC ";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
$rowforNews = mysqli_fetch_array($recodeforNews);
?>
<li><h4> <?php $str="一二三四";echo substr($str,0,3);?>、<?=$rowforNews["type_name"]?></h4><li>
<li>
<ul><?php
$selectSQLforNews = "SELECT * FROM `yu_news` WHERE `type_id`=1 ORDER BY `news_hit`DESC LIMIT 0,5";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
while ($rowforNews = mysqli_fetch_array($recodeforNews))
{
?>
<li>·<?=$rowforNews["news_title"]?>[<?=$rowforNews["news_hit"]?>]<li>
<?php
}
mysqli_free_result($recodeforNews);
?>
</ul>
</li>
<?php
$selectSQLforNews = "SELECT * FROM `yu_type` ORDER BY `type_id`=2 DESC ";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
$rowforNews = mysqli_fetch_array($recodeforNews);
?>
<li><h4> <?php $str="一二三四";echo substr($str,3,3);?>、<?=$rowforNews["type_name"]?></h4> </li>
<li>
<ul>
<?php
$selectSQLforNews = "SELECT * FROM `yu_news` WHERE `type_id`=2 ORDER BY `news_hit` DESC LIMIT 0,5";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
while ($rowforNews = mysqli_fetch_array($recodeforNews))
{
?>
<li>· <?=$rowforNews["news_title"]?>[<?=$rowforNews["news_hit"]?>] </li>
<?php
}
mysqli_free_result($recodeforNews);
?>
</ul>
</li>
<?php
$selectSQLforNews = "SELECT * FROM `yu_type` ORDER BY `type_id`=3 DESC ";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
$rowforNews = mysqli_fetch_array($recodeforNews);
?>
<li><h4><?php $str="一二三四";echo substr($str,6,3);?>、<?=$rowforNews["type_name"]?></h4> </li>
<li>
<ul><?php
$selectSQLforNews = "SELECT * FROM `yu_news` WHERE `type_id`=3 ORDER BY `news_hit` DESC LIMIT 0,5";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
while ($rowforNews = mysqli_fetch_array($recodeforNews))
{
?>
<li>·<?=$rowforNews["news_title"]?>[<?=$rowforNews["news_hit"]?>] </li>
<?php
}
mysqli_free_result($recodeforNews);
?>
</ul>
</li>
<?php
$selectSQLforNews = "SELECT * FROM `yu_type` ORDER BY `type_id`=4 DESC ";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
$rowforNews = mysqli_fetch_array($recodeforNews);
?>
<li><h4><?php $str="一二三四";echo substr($str,9,3);?>、<?=$rowforNews["type_name"]?></h4> </li>
<li>
<ul><?php
$selectSQLforNews = "SELECT * FROM `yu_news` WHERE `type_id`=4 ORDER BY `news_hit` DESC LIMIT 0,5";
$recodeforNews = mysqli_query($conn,$selectSQLforNews);
while ($rowforNews = mysqli_fetch_array($recodeforNews))
{
?>
<li>·<?=$rowforNews["news_title"]?>[<?=$rowforNews["news_hit"]?>] </li>
<?php
}
mysqli_free_result($recodeforNews);
?>
</ul>
</li>
</ul>
<?php
mysqli_close($conn);
?>
</body>
</html>
2021年06月18日 03点06分 5
1