PHP×Ô¶¯ÊÊÓ¦·¶Î§µÄÒ³Âë·ÖÒ³³ÌÐò
×÷Õß ØýÃû¼¼Êõ
À´Ô´ NET±à³Ì
ä¯ÀÀ
·¢²¼Ê±¼ä 2012-03-15
GET[''page''])?
PHP×Ô¶¯ÊÊÓ¦·¶Î§µÄÒ³Âë·ÖÒ³³ÌÐò - ÁèÖڿƼ¼
¿ìËÙÒµÎñͨµÀ
PHP×Ô¶¯ÊÊÓ¦·¶Î§µÄÒ³Âë·ÖÒ³³ÌÐò
×÷Õß ØýÃû¼¼Êõ
À´Ô´ NET±à³Ì
ä¯ÀÀ
·¢²¼Ê±¼ä 2012-03-15
|
content |
ÁèÖڿƼ¼×¨ÒµÌṩ·þÎñÆ÷×âÓᢷþÎñÆ÷Íйܡ¢ÆóÒµÓʾ֡¢ÐéÄâÖ÷»úµÈ·þÎñ£¬¹«Ë¾ÍøÕ¾£ºhttp://www.lingzhong.cn
ΪÁ˸ø¹ã´ó¿Í»§Á˽â¸ü¶àµÄ¼¼ÊõÐÅÏ¢£¬±¾¼¼ÊõÎÄÕÂÊÕ¼¯À´Ô´ÓÚÍøÂç,ÁèÖڿƼ¼×ðÖØÎÄÕÂ×÷ÕߵİæȨ£¬Èç¹ûÓÐÉæ¼°ÄãµÄ°æȨÓбØҪɾ³ýÄãµÄÎÄÕ£¬ÇëºÍÎÒÃÇÁªÏµ¡£ÒÔÉÏÐÅÏ¢ÓëÎÄÕÂÕýÎÄÊDz»¿É·Ö¸îµÄÒ»²¿·Ö,Èç¹ûÄúҪתÔر¾ÎÄÕÂ,Çë±£ÁôÒÔÉÏÐÅÏ¢£¬Ð»Ð»!
|
|
|
GET[''page'']:1; $db = new Mysql(); $counts = $db->counts(''select `id` from `test`''); $sql=''select `id`,`title` from `test`''; $getpageinfo = page($page,$counts,$phpfile); $sql.=$getpageinfo[''sqllimit'']; $data = $db->getRows($sql); ?> <?php echo $getpageinfo[''pagecode''];//ÏÔʾ·ÖÒ³µÄhtml´úÂë ?>
css
<style type="text/css"> body{font-family:Tahoma;} .page{padding:2px;font-weight:bolder;font-size:12px;} .page a{border:1px solid #ccc;padding:0 5px 0 5px;margin:2px;text-decoration:none;color:#333;} .page span{padding:0 5px 0 5px;margin:2px;background:#09f;color:#fff;border:1px solid #09c;} </style>
ÍêÉÆ£º¼ÓÁËÒ³ÂëÌøתÎı¾¿ò
<?php function page($page,$total,$phpfile,$pagesize=10,$pagelen=7){ $pagecode = '''';//¶¨Òå±äÁ¿£¬´æ·Å·ÖÒ³Éú³ÉµÄHTML $page = intval($page);//±ÜÃâ·ÇÊý×ÖÒ³Âë $total = intval($total);//±£Ö¤×ܼǼÊýÖµÀàÐÍÕýÈ· if(!$total) return array();//×ܼǼÊýΪÁã·µ»Ø¿ÕÊý×é $pages = ceil($total/$pagesize);//¼ÆËã×Ü·ÖÒ³ //´¦ÀíÒ³ÂëºÏ·¨ÐÔ if($page<1) $page = 1; if($page>$pages) $page = $pages; //¼ÆËã²éѯƫÒÆÁ¿ $offset = $pagesize*($page-1); //Ò³Â뷶Χ¼ÆËã $init = 1;//ÆðʼҳÂëÊý $max = $pages;//½áÊøÒ³ÂëÊý $pagelen = ($pagelen%2)?$pagelen:$pagelen+1;//Ò³Âë¸öÊý $pageoffset = ($pagelen-1)/2;//Ò³Âë¸öÊý×óÓÒÆ«ÒÆÁ¿ //Éú³Éhtml $pagecode=''<div class="page">''; $pagecode.="<span>$page/$pages</span>";//µÚ¼¸Ò³,¹²¼¸Ò³ //Èç¹ûÊǵÚÒ»Ò³£¬Ôò²»ÏÔʾµÚÒ»Ò³ºÍÉÏÒ»Ò³µÄÁ¬½Ó if($page!=1){ $pagecode.="<a href=\"{$phpfile}?page=1\"><<</a>";//µÚÒ»Ò³ $pagecode.="<a href=\"{$phpfile}?page=".($page-1)."\"><</a>";//ÉÏÒ»Ò³ } //·ÖÒ³Êý´óÓÚÒ³Âë¸öÊýʱ¿ÉÒÔÆ«ÒÆ if($pages>$pagelen){ //Èç¹ûµ±Ç°Ò³Ð¡ÓÚµÈÓÚ×óÆ«ÒÆ if($page<=$pageoffset){ $init=1; $max = $pagelen; }else{//Èç¹ûµ±Ç°Ò³´óÓÚ×óÆ«ÒÆ //Èç¹ûµ±Ç°Ò³ÂëÓÒÆ«ÒƳ¬³ö×î´ó·ÖÒ³Êý if($page+$pageoffset>=$pages+1){ $init = $pages-$pagelen+1; }else{ //×óÓÒÆ«Òƶ¼´æÔÚʱµÄ¼ÆËã $init = $page-$pageoffset; $max = $page+$pageoffset; } } } //Éú³Éhtml for($i=$init;$i<=$max;$i++){ if($i==$page){ $pagecode.=''<span>''.$i.''</span>''; } else { $pagecode.="<a href=\"{$phpfile}?page={$i}\">$i</a>"; } } if($page!=$pages){ $pagecode.="<a href=\"{$phpfile}?page=".($page+1)."\">></a>";//ÏÂÒ»Ò³ $pagecode.="<a href=\"{$phpfile}?page={$pages}\">>></a>";//×îºóÒ»Ò³ } $pagecode.="<input type=\"text\" size=\"3\" onkeydown=\"if(event.keyCode==13) {window.location.href=''{$phpfile}?page=''+this.value; return false;}\" /></div>"; return array(''pagecode''=>$pagecode,''sqllimit''=>'' limit ''.$offset.'',''.$pagesize); } ?>
ÒÔÏÂÊÇÐÂÊÖʹÓÃ˵Ã÷
<?php $phpfile = ''index.php'';//Ò³ÃæÎļþÃû $page= isset(
PHP×Ô¶¯ÊÊÓ¦·¶Î§µÄÒ³Âë·ÖÒ³³ÌÐò - ÁèÖڿƼ¼
¿ìËÙÒµÎñͨµÀ
PHP×Ô¶¯ÊÊÓ¦·¶Î§µÄÒ³Âë·ÖÒ³³ÌÐò
×÷Õß ØýÃû¼¼Êõ
À´Ô´ NET±à³Ì
ä¯ÀÀ
·¢²¼Ê±¼ä 2012-03-15
|
content |
ÁèÖڿƼ¼×¨ÒµÌṩ·þÎñÆ÷×âÓᢷþÎñÆ÷Íйܡ¢ÆóÒµÓʾ֡¢ÐéÄâÖ÷»úµÈ·þÎñ£¬¹«Ë¾ÍøÕ¾£ºhttp://www.lingzhong.cn
ΪÁ˸ø¹ã´ó¿Í»§Á˽â¸ü¶àµÄ¼¼ÊõÐÅÏ¢£¬±¾¼¼ÊõÎÄÕÂÊÕ¼¯À´Ô´ÓÚÍøÂç,ÁèÖڿƼ¼×ðÖØÎÄÕÂ×÷ÕߵİæȨ£¬Èç¹ûÓÐÉæ¼°ÄãµÄ°æȨÓбØҪɾ³ýÄãµÄÎÄÕ£¬ÇëºÍÎÒÃÇÁªÏµ¡£ÒÔÉÏÐÅÏ¢ÓëÎÄÕÂÕýÎÄÊDz»¿É·Ö¸îµÄÒ»²¿·Ö,Èç¹ûÄúҪתÔر¾ÎÄÕÂ,Çë±£ÁôÒÔÉÏÐÅÏ¢£¬Ð»Ð»!
|
HTTP/1.1 401 Access Denied
³ÌÈëÃÅÍø
Photoshop»æÖƸ߹âË®¾§ÖʸÐË®¾§Æ»¹û
|
|
GET[''page''])?
PHP×Ô¶¯ÊÊÓ¦·¶Î§µÄÒ³Âë·ÖÒ³³ÌÐò - ÁèÖڿƼ¼
¿ìËÙÒµÎñͨµÀ
PHP×Ô¶¯ÊÊÓ¦·¶Î§µÄÒ³Âë·ÖÒ³³ÌÐò
×÷Õß ØýÃû¼¼Êõ
À´Ô´ NET±à³Ì
ä¯ÀÀ
·¢²¼Ê±¼ä 2012-03-15
|
content |
ÁèÖڿƼ¼×¨ÒµÌṩ·þÎñÆ÷×âÓᢷþÎñÆ÷Íйܡ¢ÆóÒµÓʾ֡¢ÐéÄâÖ÷»úµÈ·þÎñ£¬¹«Ë¾ÍøÕ¾£ºhttp://www.lingzhong.cn
ΪÁ˸ø¹ã´ó¿Í»§Á˽â¸ü¶àµÄ¼¼ÊõÐÅÏ¢£¬±¾¼¼ÊõÎÄÕÂÊÕ¼¯À´Ô´ÓÚÍøÂç,ÁèÖڿƼ¼×ðÖØÎÄÕÂ×÷ÕߵİæȨ£¬Èç¹ûÓÐÉæ¼°ÄãµÄ°æȨÓбØҪɾ³ýÄãµÄÎÄÕ£¬ÇëºÍÎÒÃÇÁªÏµ¡£ÒÔÉÏÐÅÏ¢ÓëÎÄÕÂÕýÎÄÊDz»¿É·Ö¸îµÄÒ»²¿·Ö,Èç¹ûÄúҪתÔر¾ÎÄÕÂ,Çë±£ÁôÒÔÉÏÐÅÏ¢£¬Ð»Ð»!
|
|
|
GET[''page'']:1;//ĬÈÏÒ³Âë $db = mysql_connect(''localhost'',''test'',''test'');//Á´½ÓÊý¾Ý¿â mysql_select_db(''test'',$db);//Ñ¡ÔñÊý¾Ý¿â $counts = mysql_num_rows(mysql_query(''select `id` from `test`'',$db));//»ñÈ¡ÐèÒªµÄÊý¾Ý×ÜÌõÊý $sql=''select `id`,`title` from `test`'';//¶¨Òå²éѯÓï¾äSQL $getpageinfo = page($page,$counts,$phpfile);//µ÷Óú¯Êý£¬Éú³É·ÖÒ³HTML ºÍ SQL LIMIT ×Ó¾ä $sql.=$getpageinfo[''sqllimit''];//×éºÏÍêÕûµÄSQLÓï¾ä $data = $row = array();//³õʼ»¯Êý×é $result = mysql_query($sql,$db);//»ñÈ¡½á¹û¼¯ //½«Êý¾Ý×°Èë$dataÊý×é while($row = mysql_fetch_array($result)){ $data[]=$row; } ?> <?php echo $getpageinfo[''pagecode''];//ÏÔʾ·ÖÒ³µÄhtml´úÂë ?> |