时间:2021-07-01 10:21:17 帮助过:2人阅读
<title>分页查询</title> </head> <body> <h1>分页查询</h1> <br /> <?php $name=""; $fytj=""; if(!empty($_GET["name"])) { $name=$_GET["name"]; //取提交的name值 $fytj="name={$name}"; //分页查询条件 } $tj=" where Areaname like ‘%{$name}%‘ "; ?> <div> <form action="fy.php" method="get"> 输入名称: <input type="text" name="name" value="<?php echo $name;?>"/> <input type="submit" value="查询"/> </form> </div> <br /> <table width="900px" border="1" cellpadding="0" cellspacing="0"> <tr align="center"> <td>代号</td> <td>名称</td> <td>父级代号</td> </tr> <?php include("DBDA.class.php"); //调用查询方法类 include("page.class.php"); //调用分页方法类 $db=new DBDA(); $sqlall="select count(*) from chinastates".$tj; $attrall=$db->Query($sqlall); $total=$attrall[0][0]; $page=new Page($total,20,$fytj); //需要参数 1.数据总条数 $sql="select * from chinastates ".$tj.$page->limit; $attr=$db->Query($sql); foreach($attr as $v) { $rp="<span style=‘color:red‘>{$name}</span>"; $mingcheng=str_replace($name,$rp,$v[1]); echo "<tr align=‘center‘> <td>{$v[0]}</td> <td>{$mingcheng}</td> <td>{$v[2]}</td> </tr>"; } ?> </table> <div> <?php echo $page->fpage(); ?> </div> </body> </html>
分页查询结果
数据库练习——分页查询
标签: