PHP分页查询练习
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>无标题文档</title> 6 </head> 7 8 <body> 9 <div> 10 <?php 11 $name=""; 12 $tj1=""; 13 $fytj=""; 14 if(!empty($_GET["name"])) 15 { 16 $name=$_GET["name"]; 17 $fytj="name=$name"; 18 } 19 if(!empty($_POST["name"])) 20 { 21 $name=$_POST["name"]; 22 $fytj="name=$name"; 23 } 24 $tj1=" where AreaName like '%$name%' "; 25 26 27 ?> 28 29 </div> 30 <div> 31 <form action="5-12.php" method="post"> 32 <div>请输入关键字:<input type="text" value="<?php echo $name; ?>" name="name" /> 33 <input type="submit" value="查询" /> 34 </div> 35 </form> 36 </div> 37 <table width="100%" cellpadding="0" cellspacing="0" border="1"> 38 <tr> 39 <td>代号</td><td>名称</td><td>父级代号</td> 40 <?php 41 include("database.class.php"); 42 include("page.class.php"); 43 44 $db=new database(); 45 $attrall=$db->Query("select count(*) from chinastates".$tj1); 46 $total=$attrall[0][0]; 47 $page=new Page($total,15,$fytj,true); 48 $attr=$db->Query("select * from chinastates ".$tj1.$page->limit); 49 foreach($attr as $v) 50 { 51 echo "<tr><td>{$v[0]}</td><td>{$v[1]}</td><td>{$v[2]}</td></tr>"; 52 } 53 ?> 54 </tr> 55 </table> 56 <div> 57 <?php 58 59 echo $page->fpage(); 60 61 ?> 62 </div> 63 </body> 64 </html>