MyZ分页类

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。http://blog.youkuaiyun.com/mayongzhan - 马永占,myz,mayongzhan

花了点时间写了个分页类,看着还不错,测试了下能用,离实际应用应该就剩一个样式了.

_tatal等等之所以要写成带下划线,是因为这些内容需要带入到地址栏中,实际当中可能会重名

link的作用是有时得到的数据是为了使分页跳转的时候带上参数

写很比教长的时间.有点模仿小李的分页,没加样式,这样更好

<!-- 分页类 , 加测试 ~~~ -->

<? php

/* *

*@nametest.php

*@dateWedDec0521:49:45CST2007

*@copyright马永占(MyZ)

*@author马永占(MyZ)

*@linkhttp://blog.youkuaiyun.com/mayongzhan/

*/



class Pager

{

private $_tatal ; // 总数,记录的总条数

private $_nowPage = 1 ; // 当前页

private $_rows = 40 ; // 行数

private $pages ; // 页数,可以通过总数和行数计算出来

private $dataBegin = 0 ; // sql语句limit开始的数字,可以通过行数和当前页计算出来

private $dataCount = 40 ; // sql语句limit取的数据量,根据行数来决定

private $link = '' ; // 分页带的其他参数

private $showCount = 10 ; // 页码显示量

public function set_tatal( $_tatal )

{

$this -> _tatal = $_tatal ;

}

public function set_nowPage( $_nowPage )

{

$this -> _nowPage = $_nowPage ;

}

public function set_rows( $_rows )

{

$this -> _rows = $_rows ;

}

public function setLink( $link )

{

$this -> link = $link ;

}

public function setShowCount( $showCount )

{

$this -> showCount = $showCount ;

}

public function setPages()

{

$this -> pages = ( $this -> _tatal - $this -> _tatal % $this -> _rows) / $this -> _rows

+ intval ( $this -> _tatal % $this -> _rows == 0 ? 0 : 1 );

}

public function getDataBegin()

{

$this -> dataBegin = $this -> _nowPage * $this -> _rows;

return $this -> dataBegin;

}

public function getDataCount()

{

$this -> dataCount = $this -> _rows;

return $this -> dataCount;

}



public function createPager() // 创建分页

{

$pagerList = ' <div> ' ;

// 首页

if ( $this -> _nowPage > $this -> showCount && $this -> _nowPage != 1 ){

$pagerList = ' &nbsp;<ahref="? ' . $this -> link . '

&_tatal=
' . $this -> _tatal . '

&_rows=
' . $this -> _rows . '

&_nowPage=1"

title="首页">1</a>&nbsp;...
' ;

}

// 前翻N页

if ( $this -> _nowPage > $this -> showCount){

$pagerList .= ' &nbsp;<ahref="? ' . $this -> link . '

&_tatal=
' . $this -> _tatal . '

&_rows=
' . $this -> _rows . '

&_nowPage=
' . ( $this -> _nowPage - $this -> showCount) . ' "

title="前
' . $this -> showCount . ' 页"><<</a> ' ;

}

// 前1页

if ( $this -> _nowPage != 1 ){

$pagerList .= ' &nbsp;<ahref="? ' . $this -> link . '

&_tatal=
' . $this -> _tatal . '

&_rows=
' . $this -> _rows . '

&_nowPage=
' . ( $this -> _nowPage - 1 ) . ' "

title="前1页"><</a>
' ;

}

$nowPageGroup = $this -> nowPageGroup(); // 得到当前页大分页

$beginNowPage = ( $nowPageGroup - 1 ) * $this -> showCount + 1 ; // 得到开始的页码

$i = 0 ;

while ( $beginNowPage <= $this -> pages && $i < 10 ){

if ( $beginNowPage != $this -> _nowPage){

$pagerList .= ' &nbsp;<ahref="? ' . $this -> link . '

&_tatal=
' . $this -> _tatal . '

&_rows=
' . $this -> _rows . '

&_nowPage=
' . $beginNowPage . ' "

title="第
' . $beginNowPage . ' 页"> ' . $beginNowPage . ' </a> ' ;

}

else {

$pagerList .= ' &nbsp; ' . $beginNowPage ;

}

$i ++ ;

$beginNowPage ++ ;

}

// 后1页

if ( $this -> _nowPage != $this -> pages){

$pagerList .= ' &nbsp;<ahref="? ' . $this -> link . '

&_tatal=
' . $this -> _tatal . '

&_rows=
' . $this -> _rows . '

&_nowPage=
' . ( $this -> _nowPage + 1 ) . ' "

title="后1页">></a>
' ;

}

// 后翻N页

if ( $this -> pages > $this -> showCount && $this -> lastShow()){

$pagerList .= ' &nbsp;<ahref="? ' . $this -> link . '

&_tatal=
' . $this -> _tatal . '

&_rows=
' . $this -> _rows . '

&_nowPage=
' . ( $this -> _nowPage + $this -> showCount) . ' "

title="后
' . $this -> showCount . ' 页">>></a> ' ;

}

// 末页

if ( $this -> pages > $this -> showCount && $this -> lastShow()){

$pagerList .= ' &nbsp;...&nbsp;<ahref="? ' . $this -> link . '

&_tatal=
' . $this -> _tatal . '

&_rows=
' . $this -> _rows . '

&_nowPage=
' . $this -> pages . ' "

title="末页">
' . $this -> pages . ' </a> ' ;

}

$pagerList .= ' &nbsp;&nbsp;&nbsp;( ' ;

$pagerList .= ' 跳转到<inputname="custompage"size="3"value=" ' . $this -> _nowPage . ' "onkeydown="if(event.keyCode==13){window.location= ' ? ' .$this->link. ' & _tatal = ' .$this->_tatal. ' & _rows = ' .$this->_rows. ' & _nowPage = ' +this.value+ '' ;returnfalse;}"type="text"/>/ ' . $this -> pages;

$pagerList .= ' ,每页<inputname="custompage"size="3"value=" ' . $this -> _rows . ' "onkeydown="if(event.keyCode==13){window.location= ' ? ' .$this->link. ' & _tatal = ' .$this->_tatal. ' & _rows = ' +this.value+ ' & _nowPage = 1 ' ;returnfalse;}"type="text"/>行/ ' . $this -> _rows;

$pagerList .= ' )</div> ' ;

return $pagerList ;

}



private
解释 int nSize = pdPoints.size(); if (nSize < 3) { return; } vector<double>vdX; vector<double>vdY; double dMeanX = 0, dMeanY = 0; for (Point2d p : pdPoints) { vdX.push_back(p.x); vdY.push_back(p.y); dMeanX += p.x; dMeanY += p.y; } dMeanX /= (nSize * 1.); dMeanY /= (nSize * 1.); double Xi = 0, Yi = 0, Zi = 0; double Mz = 0, Mxy = 0, Mxx = 0, Myy = 0, Mxz = 0, Myz = 0, Mzz = 0, Cov_xy = 0, Var_z=0; double A0 = 0, A1 = 0, A2 = 0, A22 = 0; double Dy = 0, xnew = 0, x = 0, ynew = 0, y = 0; double DET = 0, Xcenter = 0, Ycenter = 0; for (int i = 0; i < nSize; i++) { Xi = vdX[i] - dMeanX; // centered x-coordinates Yi = vdY[i] - dMeanY; // centered y-coordinates Zi = Xi * Xi + Yi * Yi; Mxy += Xi * Yi; Mxx += Xi * Xi; Myy += Yi * Yi; Mxz += Xi * Zi; Myz += Yi * Zi; Mzz += Zi * Zi; } Mxx /= (nSize * 1.); Myy /= (nSize * 1.); Mxy /= (nSize * 1.); Mxz /= (nSize * 1.); Myz /= (nSize * 1.); Mzz /= (nSize * 1.); Mz = Mxx + Myy; Cov_xy = Mxx * Myy - Mxy * Mxy; Var_z = Mzz - Mz * Mz; A2 = 4.0 * Cov_xy - 3.0 * Mz * Mz - Mzz; A1 = Var_z * Mz + 4.0 * Cov_xy * Mz - Mxz * Mxz - Myz * Myz; A0 = Mxz * (Mxz * Myy - Myz * Mxy) + Myz * (Myz * Mxx - Mxz * Mxy) - Var_z * Cov_xy; A22 = A2 + A2; // finding the root of the characteristic polynomial // using Newton's method starting at x=0 // (it is guaranteed to converge to the right root) x = 0., y = A0; for (int i = 0; i < 99; i++) // usually, 4-6 iterations are enough { Dy = A1 + x * (A22 + 16. * x * x); xnew = x - y / Dy; if ((xnew == x) || (!isfinite(xnew))) { break; } ynew = A0 + xnew * (A1 + xnew * (A2 + 4.0 * xnew * xnew)); if (abs(ynew) >= abs(y)) { break; } x = xnew; y = ynew; } DET = x * x - x * Mz + Cov_xy; Xcenter = (Mxz * (Myy - x) - Myz * Mxy) / DET / 2.0; Ycenter = (Myz * (Mxx - x) - Mxz * Mxy) / DET / 2.0; dRadius = sqrt(Xcenter * Xcenter + Ycenter * Ycenter + Mz - x - x); pdCenter = Point2d(Xcenter + dMeanX, Ycenter + dMeanY);
06-09
# -*- coding: utf-8 -*- BOT_NAME = 'spider' SPIDER_MODULES = ['spiders'] NEWSPIDER_MODULE = 'spiders' ROBOTSTXT_OBEY = False DEFAULT_REQUEST_HEADERS = { 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Mobile Safari/537.36', 'Referer': 'https://weibo.com/', 'Cookie': 'SCF=AgqHjsCD6PFCTQvhkhDV_5xV3cOZ1wMAWHeOwlyzXHHzgee-jRWGV3da2uTTSTt4FKe-Em3JNT_p8F3b5VN81so.; SINAGLOBAL=4541434264227.427.1736433023560; SUB=_2A25KysEKDeRhGeBK7VQQ8S3LzD-IHXVpplzCrDV8PUNbmtAYLWjYkW1NR4hNkw8TOc9gC8F8IhgUf_WlGRQj-ckJ; SUBP=0033WrSXqPxfM725Ws9jqgMF55529P9D9W5VFgGklZiw-wvM2Vq2x1Z15JpX5KzhUgL.FoqXSoqpeKeNS0e2dJLoI0YLxKnLBKqL1h2LxK-L1K5L1heLxK-LBKBL12qLxK-LBKBLBK.LxKML1-2L1hBLxKnLBK-LB.qLxKML1KeL1-et; ALF=02_1744191066; WBPSESS=6Axpu1TacVAKouPlQL8eUxLX1pyDayQXzA6Te2GXxJaj9Oro1D-tweRELev6_uwlz4ip9biTlZbF2sx58BB-zVRDaBkKlmosa4LcVtxpotxtEQy7eT14vllmsl7ePx57wZ0Cuap1NeK2mYz7NJLOHQ==; ULV=1741837498210:4:2:2:7357620306498.613.1741837498194:1741652383524; XSRF-TOKEN=9CFI5izfq6XlYszxBEVEdxqS' } CONCURRENT_REQUESTS = 16 DOWNLOAD_DELAY = 3 RANDOMIZE_DOWNLOAD_DELAY = True DOWNLOADER_MIDDLEWARES = { 'scrapy.downloadermiddlewares.cookies.CookiesMiddleware': None, 'scrapy.downloadermiddlewares.redirect.RedirectMiddleware': None, 'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware': 810, # 'middlewares.IPProxyMiddleware': 100, # 如果有 IP 代理中间件 'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware': 110, } REDIRECT_ENABLED = False # 彻底关闭 302 自动重定向 # 如果有代理: # HTTP_PROXY = 'http://your_proxy_ip:port' ITEM_PIPELINES = { 'pipelines.JsonWriterPipeline': 300, } 这个是我的代码
03-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值