创建分页界面以及查询办法
<?php //分别引用分页类和连接数据库函数 include "class/page-class.php"; include "function/unionmysql-function.php"; //处理提交信息 $name=""; $tj=""; if(isset($_GET[‘name‘])) { $name=$_GET[‘name‘]; $tj=" where AreaName like ‘%{$name}%‘ "; } //获取数据库中总共有多少条数据 $sqlcount="select count(*) from chinastates".$tj; $sqlcount=unionmysql($sqlcount); $sqlcount=$sqlcount[0][0]; //初始化分页类 $page=new Page($sqlcount,15); //根据分页条件查询数据,在查询后加条件$page->limit从而达到分页效果 $sql="select * from chinastates ".$tj.$page->limit; $sql=unionmysql($sql); ?> <!--创建查询条件--> <br /> <form action="" method="get"> <div align="center"> 请输入查询条件: <input type="text" name="name" value="<?php echo $name ?>" /> <input type="submit"/> </form> </div> <br /> <!--打印表格--> <table width="1000px" border="1px" align="center" bordercolor="#00FF00"> <tr> <td>所在地</td> <td>父级代号</td> <td>root</td> </tr> <?php foreach($sql as $i) { $j="<font color=‘#FF0000‘>$name</font>"; $i[1]=str_replace("$name","$j","$i[1]"); echo"<tr> <td>$i[1]</td> <td>$i[2]</td> <td>$i[3]</td> </tr>"; } ?> </table> <br /> <div align="center"><?php echo $page->fpage() ?></div>
时间: 2024-10-19 02:02:41