分页查询:使用分页类查询 用get传值

<body>
<?php
$cx = "";
if(!empty($_GET["cx"]))                                          //判断get传过来的值非空,那么把传过来的值赋给变量$cx
{
    $cx = $_GET["cx"];    
}
?>
<form action="fenyechaxun.php" method="get">
关键字:<input type="text" name="cx" value="<?php echo $cx; ?>" /><input type="submit" value="查询" />  //把用户输入的关键字留在文本框'text'中
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
    <td>areacode</td>
    <td>areaname</td>
    <td>parentareacode</td>
    <td>root</td>
    <td>zone</td>
    <td>nacigateurl</td>
</tr>
<?php
include("../fzl/czy.class.php");
$db = new czy();
$tj = " 1=1 ";                                 //条件$tj=' 1=1 '时,点搜索是搜索全部;
if(!empty($_GET["cx"] )&& $_GET["cx"] !="")                //如果get传过来的值 $_GET["cx"]非空且不是空的字符串是 把$tj 加在sql语句后边
{
    $tj = " areaname like '%{$_GET['cx']}%' ";    
}
$stotal = " select count(*) from chinastates where {$tj} ";       //求数据库的总条数
$arr = $db->strQuery($stotal);
include("../fzl/page.class.php");
$page = new Page($arr,20);
$sql = " select * from chinastates where {$tj} ".$page->limit;     //分页分页
$attr = $db->Query($sql);
foreach($attr as $v)
{
    echo "<tr>
            <td>{$v[0]}</td>
            <td>{$v[1]}</td>
            <td>{$v[2]}</td>
            <td>{$v[3]}</td>
            <td>{$v[4]}</td>
            <td>{$v[5]}</td>
          </tr>";    
}
?>
</table>
</form>
<?php
echo $page->fpage();                             //分页分页
?>
</body>

 

posted on 2016-11-09 19:58  向前看!明天会更好!  阅读(330)  评论(0编辑  收藏  举报