批改状态:合格
老师批语:同在这个小后台看上去像点样了, 不是吗?
http://xuanransoftware.com/phpStudy/0513/

<?phpclass PageList{public static $page;//当前要显示第几页public static $pageNum = 10;//一页需要显示几条数据public static $pageSum;//共有几页数据要显示public static $offset;//查询记录的偏移量,select中的offest参数public static $prevPage;//上一页public static $nextPage;//下一页public static $startPage;//页码开始的页数public static $endPage;//页码结束的页数public static $offsetPage;//页码的偏移的数量public static $showPages = 5;//一共显示的页码数public static $startOmit;//页码省略的开始标记public static $endOmit;//页码省略的结束标记public static $res;//数据库中表的结果集public function __construct($res,$page){//获取数据库表中所有的结果集PageList::$res = $res;//总页数PageList::$pageSum = ceil(count(PageList::$res)/PageList::$pageNum);//获取当前显示的是第几页//如果当前页码<1,当前页为第一页if($page<1):$page = 1;endif;//如果当前页>总页数,当前面为最后一页if($page>PageList::$pageSum):$page = PageList::$pageSum;endif;PageList::$page = $page;//查询记录的偏移量,select中的offest参数PageList::$offset = (PageList::$page-1)*PageList::$pageNum;//上一页$prev = (PageList::$page)-1;PageList::$prevPage = ($prev<1) ? 1 : $prev;//下一页$next = PageList::$page+1;PageList::$nextPage = ($next>PageList::$pageSum) ? (PageList::$pageSum) : $next;//页码的偏移量PageList::$offsetPage = (PageList::$showPages-1)/2;//页码开始和结束页数,页码开始和结束的省略标记PageList::$startPage = 1;PageList::$endPage = PageList::$pageSum;PageList::$startOmit = null;PageList::$endOmit = null;//如果(总页数>显示的页码数量)则 设置开始结束页码和开始结束省略标记if(PageList::$pageSum>PageList::$showPages):// 如果(当前页>页码偏移量+1) 则 显示 开始省略标记if((PageList::$page)>(PageList::$offsetPage+1)):PageList::$startOmit = '...';endif;// 重置开始和结束的页码//如果(当前页>页码偏移量)if(PageList::$page>PageList::$offsetPage)://起始页码=当前页-页码偏移量PageList::$startPage = PageList::$page - PageList::$offsetPage;//结束页码=当前面+页码偏移量PageList::$endPage = PageList::$page + PageList::$offsetPage;//如果(结束页码>总页数),则结束页码=总页数if(PageList::$endPage>PageList::$pageSum) :PageList::$endPage = PageList::$pageSum;endif;else://如果(当前页<页码偏移量),则 起始页码=第一页 结束页码=显示的页码数量PageList::$startPage = 1;PageList::$endPage = PageList::$showPages;endif;// 如果(当前页 + 偏移量) > 总页数if((PageList::$page+PageList::$offsetPage)>(PageList::$pageSum)):// 原理, 就是向当前页前面进行借位//(新的起始页码)=现在的起始页码-(当前页+页码偏移量-现在的结束页码)PageList::$startPage = PageList::$startPage-(PageList::$page+PageList::$offsetPage-PageList::$endPage);endif;// 如果 (显示页码数量<总页数)&&((当前页+页码偏移量)<总页数) 显示结束省略标记if((PageList::$showPages<PageList::$pageSum)&&((PageList::$page+PageList::$offsetPage)<PageList::$pageSum)):PageList::$endOmit = '...';endif;endif;}}?>
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="stylesheet" href="css/select.css"><title>商品查询页</title></head><body><div class="show"><div class="row"><div>商品编号</div><div>商品名称</div><div>商品价格</div><div>上架时间</div></div><?phprequire 'autoLoad.php';use compotents\conn\DBconn;//连接数据库,查询商品表中数据$conn = new DBconn();$table = 'tb_goods';//表名$records = $conn->select($table);//查询表中所有数据require 'pageList.php';$page = $_GET['page'] ?? 1;//设置当前访问的页数,默认是第一页$pageList = new PageList($records,$page);$records = $conn->select($table,'*','*',$pageList::$pageNum,$pageList::$offset);//查询表中当页数据foreach($records as $res):?><div class="row"><div><?php echo $res['id']; ?></div><div><?php echo $res['name']; ?></div><div><?php echo $res['price'],'元/',$res['unit']; ?></div><div><?php echo $res['sdate']; ?></div></div><?phpendforeach;?><!-- 分页条 --><div class="pagelist"><!-- 上一页 --><a href="<?php echo $_SERVER['PHP_SELF'] . '?page=' . $pageList::$prevPage ?>">上一页</a><?php$self = $_SERVER['PHP_SELF'];//开始省略标记if(isset($pageList::$startOmit)):echo "<a href='{$self}?page=1'>1</a>";// 如果起始页就是第2页,则不显示第二页if($pageList::$startPage !== 2):echo "<a href='{$self}?page=2'>2</a>";endif;echo '<a href="">...</a>';endif;//中间显示的页码数for ($i = $pageList::$startPage;$i<=$pageList::$endPage;$i++):if( $i ==$pageList::$page):echo "<a href='{$self}?page={$i}' class='pageActive'>{$i}</a>";else:echo "<a href='{$self}?page={$i}'>{$i}</a>";endif;endfor;//结束省略标记if(isset($pageList::$endOmit)):$sumPrev =intval($pageList::$pageSum-1) ;//总页数的上一面echo '<a href="">...</a>';if($pageList::$endPage !== $sumPrev):echo "<a href='{$self}?page={$sumPrev}'>{$sumPrev}</a>";endif;echo "<a href='{$self}?page={$pageList::$pageSum}'>{$pageList::$pageSum}</a>";endif;?><!-- 下一页 --><a href="<?php echo $_SERVER['PHP_SELF'] . '?page=' . $pageList::$nextPage ?>">下一页</a><form action="<?php echo $self; ?>" method="GET"><input type="number" name="page" id="page" value="1"><button type="submit">GO</button></form></div></div></body></html>
<?phpsession_start();if(!(isset($_SESSION['userNc']))):exit('<script>alert("您还未登录,请登录后操作");location.href="session/login.php";</script>');endif;?><!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="stylesheet" href="css/select.css"><title>商品修改页</title></head><body><div class="show"><div class="row"><div>商品编号</div><div>商品名称</div><div>价格/单位</div><div>上架时间</div><div>更新操作</div></div><?phprequire 'autoLoad.php';use compotents\conn\DBconn;//连接数据库,查询商品表中数据$conn = new DBconn();$table = 'tb_goods';//表名$records = $conn->select($table);//查询表中所有数据require 'pageList.php';$page = $_GET['page'] ?? 1;//设置当前访问的页数,默认是第一页$pageList = new PageList($records,$page);$records = $conn->select($table,'*','*',$pageList::$pageNum,$pageList::$offset);//查询表中当页数据foreach($records as $res):?><div class="row"><form action="handle.php?action=update&id=<?php echo $res['id']; ?>" method="POST"><div style="width:100px"><?php echo $res['id']; ?></div><input type="text" name="goodsName" id="goodsName" style="width:120px"value="<?php echo $res['name']; ?>"><div><input type="text" name="goodsPrice" id="goodsPrice" style="width:50px"value="<?php echo $res['price']; ?>">/<input type="text" name="goodsUnit" id="goodsUnit" style="width:50px"value="<?php echo $res['unit']; ?>"></div><input type="date" name="goodSdate" id="goodSdate" style="width:120px"value="<?php echo $res['sdate']; ?>"><div style="width:120px"><button type="submit">修改</button></div></form></div><?phpendforeach;?><!-- 分页条 --><div class="pagelist"><!-- 上一页 --><a href="<?php echo $_SERVER['PHP_SELF'] . '?page=' . $pageList::$prevPage ?>">上一页</a><?php$self = $_SERVER['PHP_SELF'];//开始省略标记if(isset($pageList::$startOmit)):echo "<a href='{$self}?page=1'>1</a>";// 如果起始页就是第2页,则不显示第二页if($pageList::$startPage !== 2):echo "<a href='{$self}?page=2'>2</a>";endif;echo '<a href="">...</a>';endif;//中间显示的页码数for ($i = $pageList::$startPage;$i<=$pageList::$endPage;$i++):if( $i ==$pageList::$page):echo "<a href='{$self}?page={$i}' class='pageActive'>{$i}</a>";else:echo "<a href='{$self}?page={$i}'>{$i}</a>";endif;endfor;//结束省略标记if(isset($pageList::$endOmit)):$sumPrev =intval($pageList::$pageSum-1) ;//总页数的上一面echo '<a href="">...</a>';if($pageList::$endPage !== $sumPrev):echo "<a href='{$self}?page={$sumPrev}'>{$sumPrev}</a>";endif;echo "<a href='{$self}?page={$pageList::$pageSum}'>{$pageList::$pageSum}</a>";endif;?><!-- 下一页 --><a href="<?php echo $_SERVER['PHP_SELF'] . '?page=' . $pageList::$nextPage ?>">下一页</a><form action="<?php echo $self; ?>" method="GET"><input type="number" name="page" id="page" value="1"><button type="submit">GO</button></form></div></div></body></html>
<?phpsession_start();if(!(isset($_SESSION['userNc']))):exit('<script>alert("您还未登录,请登录后操作");location.href="session/login.php";</script>');endif;?><!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="stylesheet" href="css/select.css"><title>商品删除页</title></head><body><div class="show"><div class="row"><div>商品编号</div><div>商品名称</div><div>商品价格</div><div>上架时间</div><div>删除操作</div></div><?phprequire 'autoLoad.php';use compotents\conn\DBconn;//连接数据库,查询商品表中数据$conn = new DBconn();$table = 'tb_goods';//表名$records = $conn->select($table);//查询表中所有数据require 'pageList.php';$page = $_GET['page'] ?? 1;//设置当前访问的页数,默认是第一页$pageList = new PageList($records,$page);$records = $conn->select($table,'*','*',$pageList::$pageNum,$pageList::$offset);//查询表中当页数据foreach($records as $res):?><div class="row"><div><?php echo $res['id']; ?></div><div><?php echo $res['name']; ?></div><div><?php echo $res['price'],'元/',$res['unit']; ?></div><div><?php echo $res['sdate']; ?></div><div><a href="handle.php?action=delete&id=<?php echo $res['id']; ?>">删除</a></div></div><?phpendforeach;?><!-- 分页条 --><div class="pagelist"><!-- 上一页 --><a href="<?php echo $_SERVER['PHP_SELF'] . '?page=' . $pageList::$prevPage ?>">上一页</a><?php$self = $_SERVER['PHP_SELF'];//开始省略标记if(isset($pageList::$startOmit)):echo "<a href='{$self}?page=1'>1</a>";// 如果起始页就是第2页,则不显示第二页if($pageList::$startPage !== 2):echo "<a href='{$self}?page=2'>2</a>";endif;echo '<a href="">...</a>';endif;//中间显示的页码数for ($i = $pageList::$startPage;$i<=$pageList::$endPage;$i++):if( $i ==$pageList::$page):echo "<a href='{$self}?page={$i}' class='pageActive'>{$i}</a>";else:echo "<a href='{$self}?page={$i}'>{$i}</a>";endif;endfor;//结束省略标记if(isset($pageList::$endOmit)):$sumPrev =intval($pageList::$pageSum-1) ;//总页数的上一面echo '<a href="">...</a>';if($pageList::$endPage !== $sumPrev):echo "<a href='{$self}?page={$sumPrev}'>{$sumPrev}</a>";endif;echo "<a href='{$self}?page={$pageList::$pageSum}'>{$pageList::$pageSum}</a>";endif;?><!-- 下一页 --><a href="<?php echo $_SERVER['PHP_SELF'] . '?page=' . $pageList::$nextPage ?>">下一页</a><form action="<?php echo $self; ?>" method="GET"><input type="number" name="page" id="page" value="1"><button type="submit">GO</button></form></div></div></body></html>
<?phprequire 'autoLoad.php';use compotents\conn\DBconn;$user =new DBconn();$table = 'tb_goods';//表名$where =''; //判断的条件$data =[];//添加或者更新的数据$action = $_GET['action'];switch ($action){case 'insert':$name = $_POST['goodsName'];$price = $_POST['goodsPrice'];$unit = $_POST['goodsUnit'];$date = $_POST['goodsSdate'];$data = ['name'=>"$name",'price'=>"$price",'unit'=>"$unit",'sdate'=>"$date"];$user->insert($table,$data);break;case 'update':$id = $_GET['id'];$name = $_POST['goodsName'];$price = $_POST['goodsPrice'];$unit = $_POST['goodsUnit'];$sdate = $_POST['goodSdate'];$where = "`id`=$id";$data = ['name'=>"$name",'price'=>"$price",'unit'=>"$unit",'sdate'=>"$sdate"];$user->update($table,$data,$where);break;case 'delete':$id = $_GET['id'];$where = "`id`=$id";$user->delete($table,$where);break;default:echo '不支持此操作';}?>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号