PHP - 搜索、分页

classify.php 核心代码

<?php
    $keyword = isset($_REQUEST['keyword'])?$_REQUEST['keyword']:"";
?>
<div>
    <form action="classify.php" method="get" id="search-form">
        <input type="text" name="keyword" value="<?php echo $keyword;?>" id="keywords"/>
        <input type="button" value="搜索" onclick="search()"/>
    </form>
</div>
<script>
    function search(){
        $('#search-form').submit();
    }
</script>
<?php
    $uuid = $_COOKIE['uuid'];
    //查询语句
    $select = " SELECT * FROM classify WHERE uuid = '".$uuid."' ";
    //数据总数
    $count = " SELECT count(*) FROM classify WHERE uuid = '".$uuid."' ";
    if($keyword != ""){
        $select .= " AND name like '%".$keyword."%' ";
        $count .= " AND name like '%".$keyword."%' ";
    }
    $count = mysql_query($count);
    $count = mysql_fetch_assoc($count);
    $count = $count['count(*)'];
    //获取页面数
    $page = isset($_REQUEST['page'])?intval($_REQUEST['page']):1;
    //每页数量
    $pagesize = 10;
    //总页数
    $pages = ceil($count/$pagesize);
    if($page < 1){
        $page = 1;
    }
    if($page > $pages){
        $page = $pages;
    }
    //排序
    $order = " ORDER BY id DESC ";
    //偏移量
    $offset = ($page - 1)*$pagesize;
    $limit = " LIMIT ".$offset.", ".$pagesize;
    //最后查询语句
    $select .= $order.$limit;
    //查询
    $classify = mysql_query($select);
    if($classify){
        while ($row = mysql_fetch_assoc($classify)){
            $result[] = $row;
        }
    }
    if(empty($result)){
        echo "未查询到信息";
    }else{
        foreach ($result as $key => $val){
            echo $val['name'];
        }
    }
?>
<a>共<?php echo $count;?>条数据</a>
<a>共<?php echo $pages;?>页</a>
<a>当前第<?php echo $page;?>页</a>
<a onclick="jump(1)">首页</a>
<a onclick="jump( <?php echo $page;?> - 1 )">上一页</a>
<a onclick="jump( <?php echo $page;?> + 1 )">下一页</a>
<a onclick="jump( <?php echo $pages;?> )">尾页</a>
<input type="text" id="Pnum" />
<input type="button" value="GO" onclick="go();" />
<script>
    var keyword;
    $(document).ready(function(){
        keyword = $('#keywords').val();
    });
    function jump(page){
        window.location.href = "?keyword=" + keyword + "&page=" + page;
    }
    function go(){
        var goPage = $('#Pnum').val();
        window.location.href = "?keyword=" + keyword + "&page=" + goPage;
    }
</script>
返回文章列表 打赏
ct"style> var 15t>
打赏 $("#gray t;尾
$("f (Lo)runk("5/ filylep,"grayscale(.)>
$("f (Lo)runk("filylep," id:DXImg/>T.6875rem.Microsoft.BasicImg/>(grayscale=.)>
}ot;go();" ode">打赏 $("#cgray t;尾 $("f (Lo)runk("5/ filylep,"grayscale(0)> $("f (Lo)runk("filylep," id:DXImg/>T.6875rem.Microsoft.BasicImg/>(grayscale=0)> }ot;go();" t/javascmuy6viz3/ 忠haky /larget="no"a"ref="http W at ://deohowW at "style> enub-family:' Lic S687 MS'tle();

(●'◡'●)ノ♥ dp="form双球 • / gi>5%8E%9F%E5%88%9B/">原创


♥ da ☆♡♪ start-->5%8E%9F%E5%88%9B/">原创
☆>5%8E%9F%E5%88 prcenter>
♫>5%8E%9F%E5%88wwwrunk88创hr stylectio -义">♡>5%8E%9F%E5%88ess".luia-hidden="true">hr styleiv cla编辑');">♪>5%8E%9F%E5%88%9B/">原创 ♬> iygray >默认主题> igray >灰色主题> i 2 条评论 start- ia-hidd g 相关登录 部 start-pig>代码Clarget="ia-hiudio-->
&/lar;ddaig>代码 8ia-hiudi ?', "")tod += "Dt.se么?', "")tod Year od FullYeare么?', "")tod Mnubh od Mnubhe么?', "")tod Dt.s od Dt.se么?', "")tod H); od H); comment-reply-lin "")tod Minute od Minutetomment-reply-lin "")tod Se d od Se dtomment-rent-reply-lin "")t1 Dt.s.UTC( ,2,11,00,00,00mment-reply-lin "")t2 Dt.s.UTC(tod Year,tod Mnubh,tod Dt.s,tod H); ,tod Minute,tod Se dmment-reply-lin "")if ( 2-t1start--> ?', "")if (Yeart($_endChild(e)if (/yeartmment-reply-lin "")if (Days =)endChild(e))if (/days)-if (Yeart*36mment-reply-lin "")if (Hourt($_endChild(e))if (-(if (Yeart*36+if (Days)*days)/hourtmment-reply-lin "")if (Minutet($_endChild(e))if (-(if (Yeart*36+if (Days)*days-if (Hourt*hourtm/minutetmment-reply-lin "")if (Se ds获endChild(e))if (-(if (Yeart*36+if (Days)*days-if (Hourt*hourt-if (Minutet*minutetm/ e dsmment-reply-lin5; docript ") O.length; e++) >代码'/larget="no"a'>小尾巴o活了- ia-hi" + ent-reply-lin" ="transla'/larget="a'i" + (if (Yeart*36 + if (Days)[Mat于" + ent-reply-lin" =>代码'/larget="no"a'>天ia-hi" + ent-reply-lin" ="transla'/larget="a'i" + if (Hourt(Mat于" + ent-reply-lin" =>代码'/larget="no"a'>小时ia-hi" + ent-reply-lin" ="transla'/larget="a'i" + if (Minutet(Mat于" + ent-reply-lin" =>代码'/larget="no"a'>分ia-hi" + ent-reply-lin" ="transla'/larget="a'i" + if (Se dsMat于" + ent-reply-lin" =>代码'/larget="no"a'>秒- ia-hi" f.appendChild(inorip oc f.t/javascriviz3/ 代码 / #">加载[0.0108 =>up>s>up>] da } 加载iv cla 部 s 球 post-qr-code">/o" aria-hidd  2 d inpu">post-qr-code">/o" aria-hidd  3 d inpu">post-qr-code">/o" aria-hidd  4 d inpu">post-qr-code">/o" aria-hidd  5 d inpu">post-qr-code">/o" aria-hidd  6 d inpu">post-qr-code">/o" aria-hidd  7 d inpu">post-qr-code">/o" aria-hidd  8 d inpu">post-qr-code">/o" aria-hidd  9 d inpu">post-qr-code">/o" aria-hidd  10 d inpu">post-qr-code">/o" aria-hidd  11 d inpu">post-qr-code">/o" aria-hidd  12 d inpu">post-qr-co added = true; } }); 8 = _hmt || [] ^  迷于声音 ]:no"(a[" aria-hidden="emen[no-pjax])ribute('value', coid) : ' / { dividefrg/sert: ' / { dividet : 8000 f.appendChild(in).on('pjax:t;尾',response, holder);nt-reply var.doPJAXC;尾Aonse, h你自己的问题--> }).on('pjax:s',response, holder);nt-reply var.doPJAXSAonse, h你自己的问题--> }).on('pjax: endCJaxrHub.Queue([" set",endCJaxrHub,"f (Lo var el = d自己的问题--> })ment-reply-linnnnn$e">打赏 ded = false; $.} ') s/js/xwb/jianfan.js-rtyle.displale.displ "")i Encoss">6'+'0'//默认是否体,0 体,1-体 l "") De '0'//延迟时间,若不在前, ass=定延迟翻译时间, 如100 100ms,默认为0 l "")cookieDo">NP e++ ',rmt || []; tcut i "]0.2)tt ('o-->',rmt || []; hent.getE//5; wrrip("复制成功~\n - 请注明议” "+5; ; + keywoo-->hent.getEc($clry($nerText = ""Se.$of adcu//IE10ment.getE e.$of adinnerText = ""Se.$of ad hent.getEalertu"复制成功~\n若 - 请注明议” "+5; ; + keywoo-->hent.getEc($clry($nerText =se.$of adcu//IE6+10-ment.getE e.$of adinnerText = e.$of adt.php/aRange(). ent.getEalertu"复制成功~\n若 - 请注明议” "+5; ; + keywoo-->hent.getEc($clument.getE e.$of adfore ent.getEalertu"oading');兼 shado导致复制p败!"c f.t act//提 复制成功iv cla hf ( e.$of adt RangeAt(0 tinsonAncestorC .n = "PRE"orms newo" O.length; e++itemp" + newo" O.length; Mattemp" } newo" O.length; +e++id id 若 - 请注明议”iv> '" + 5; ; + keywoo--> Mat'i" + i; ; + keywoo--> Mat于&/lar; 迷于声音 e.$of adt e.$ofAllCinpu vatnewo" h d=" ded =df (L_e//将m('comment-fonewo" h }, 200mme}).style.displa 复制petitle加="heig mysq 部 s 向下滚动,顶部议现滚动ch ( } 剩余长度 p://omuy6g> = 'no= _hmt || []