欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

PHP——MySQL数据库分页查询

程序员文章站 2022-04-12 13:14:42
...

原理

 https://blog.csdn.net/weixin_43272781/article/details/101319460

效果 

PHP——MySQL数据库分页查询

 

代码 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<head>
	<TITLE>查询</TITLE>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<META content="text/html; charset=UTF-8" http-equiv=Content-Type>
	<LINK rel=stylesheet type=text/css href="./assets/css/index.css">
</head>
<BODY>
<DIV id=page>
    <DIV id=header>
        <DIV id=headerimg>
        <H1>维修预约</H1>
        <DIV class=description>计算机协会——维修部</DIV>
        </DIV>
	</DIV>
	<?php
		include 'conn.php';
	?>
	<HR>
    <DIV id=content class=widecolumn>
		<H2>全部预约</H2>
		<?php
			$rstot=mysqli_query($connID,"select * from wxyy order by 时间 DESC");
			$rows=mysqli_num_rows($rstot);
			mysqli_free_result($rstot);
			$pageSize=5;
			$allpage=(int)((float)($rows)/$pageSize);
			if ($allpage*$pageSize <$rows){
				$allpage=$allpage+1;
			}
			if (isset($_GET["pageNo"])){
				$pageNo=$_GET["pageNo"];
			}else{
				$pageNo=1;
			}
			if (is_numeric($pageNo))
				$pageNo=(int)$pageNo;
			else 
				$pageNo=1;
			if( $pageNo < 0)
				$pageNo=1;
			if ($pageNo > $allpage)
				$pageNo=$allpage;
			$rs=mysqli_query($connID,"select * from wxyy order by 时间 DESC limit ".($pageNo-1)*$pageSize.",".$pageSize);
			//echo "select * from wxyy order by 时间 DESC limit ".($pageNo-1)*$pageSize.",".$pageSize;
			if(mysqli_num_rows($rs)==0){
		?>
        <DIV class="postmetadata alt">
        	没有任何预约  
			<hr  style='display:block'>
		</DIV> 
		<?php
			}else{
				echo "<br>";
				echo "<br>" ;
				echo "<hr style='display:block'>";
				while($row=mysqli_fetch_assoc($rs)){
				//echo "<p>";
				//echo var_dump($row);
		?>
				<table  width="100%" border="0">
				<tr><td width="15%">预约编号: </td><td width="15%"><?php echo $row["ID"]?> </td><td>预约时间:<?php echo date("Y-m-d H:i:s",strtotime($row["时间"]));?>  </td></tr>
				<tr><td>基本信息: </td>
					<td colspan="3"><?php echo $row["姓名"]."|".$row["电话"]."|".$row["QQ"]."|" . $row["地址"] ?> </td>
				</tr>
				<tr><td>问题描述: </td>
					<td colspan="3"><?php echo $row["故障描述"]?> </td>
				</tr>
				<tr>
					<td>完成情况: </td>
					<td>
					<a href="javascript:void(0);" οnclick="window.open ('done.asp?ID=<?php echo $row["ID"]?>', 'newwindow', 'height=600, width=800, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no') ">
						<?php
							if(empty( $row["维修时间"]) Or  $row["维修时间"]="")
								echo	"未完成" ;
							else
								echo	"已完成" . "</td><td>维修人:" . $row["维修人员"];
						?>		
						</a> 
					</td>
				</tr>
				</table>
		<?php
				echo "<hr style='display:block'>";
				}
				mysqli_free_result($rs);
				mysqli_close($connID);
			}
		?>
      	<center>
		<a href="note.php?pageNo=1"><input name="firstpage" type="button" id="firstpage" value="首页"></a>
		<?php
			if ($pageNo>1)
				echo "<a href='note.php?pageNo=" . ($pageNo-1) . "'><input name='prepage' type='button' id='prepage' value='上一页'></a>";
		?>
      	页码:  
	    <?php
			for($i=$pageNo-2;$i<=$pageNo+2;$i++)
				if ($i>0 and $i <= $allpage)
					echo "<a href=note.php?pageNo=" . $i . ">" . $i . "</a>&nbsp;&nbsp;";
		?>
		
		<input name="pageno" type="text" id="pageno" size="1">页
		
		<?php
			if ($pageNo < $allpage)
				echo "<a href='note.php?pageNo=" . ($pageNo+1) . "'><input name='netpage' type='button' id='netpage' value='下一页'></a>";
		?>
		<?php
			echo "<a href='note.php?pageNo=" . $allpage . "'><input name='endpage' type='button' id='endpage' value='末页'></a>";
		?>
		
		</center>
    </DIV>

	<HR>
    <DIV id=footer>
    	<P>Copyright&copy; 2019 ZSTUCA<BR><a href="http://www.beian.miit.gov.cn/">浙ICP备19031217号-1</a> </P>
    </DIV>
</DIV>
</BODY>
</HTML>

参考文章

https://blog.csdn.net/weixin_43272781/article/details/101319460

https://blog.csdn.net/wyh0930/article/details/83543035

https://blog.csdn.net/ccy1995414/article/details/80974545