码迷,mamicode.com
首页 > 其他好文 > 详细

第六十六天上课 分页查询

时间:2016-05-13 11:11:14      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:

创建分页界面以及查询办法

<?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>

 

第六十六天上课 分页查询

标签:

原文地址:http://www.cnblogs.com/lovling/p/5484744.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!