<!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> <style type="text/css"> .res_td{ border: 1px solid silver; } table{ border-collapse:collapse;width: 400px;height:80px;border: 1px solid silver; } .res_title{ border: 1px solid silver;color:orange; } .res_bottom{ border: 1px solid silver;text-align: center; } .res_bottom a{ text-decoration: none;color: blue; } </style> </head> <body> <?php include('conn.php'); //初始化参数,三元操作符中?代表是,而:代表否 $page=isset($_GET['page'])?$_GET['page']:0; $page_size = 5; $count_res = mysql_query("select * from userinfo",$link); $count = mysql_num_rows($count_res); $maxpage = ceil($count / $page_size)-1; $minpage = 0; //判断传入的$page参数 $pagenext = $page==$maxpage?$maxpage:$page+1; $pagepre = $page ==0?$page:$page-1; //构造查询语句 $str_sql = "select * from userinfo limit ".$page*$page_size.",".$page_size; $res = mysql_query($str_sql); echo "<table>"; echo "<tr><td class='res_title'>ID</td><td class='res_title'>姓名</td>"; echo "<td class='res_title'>密码</td><td class='res_title'>年龄</td></tr>"; while($rows = mysql_fetch_assoc($res)){ echo "<tr><td class='res_td'>$rows[id]</td><td class='res_td'>$rows[name]</td>"; echo "<td class='res_td'>$rows[password]</td><td class='res_td'>$rows[age]</td></tr>"; } echo "<tr><td class='res_bottom' colspan='2'><a href='page.php?page=".$pagepre."'>前一页"; echo "</a></td><td class='res_bottom' colspan='2'><a href='page.php?page=".$pagenext."'>后一页</a></td><tr/>"; echo "</table>"; ?> </body> </html>