conn, $sql); return mysqli_fetch_all($query, MYSQLI_ASSOC); }}$obj = new Mynews;?>display post: readAllarticles() as $art) { extract($art); ?> Now i want a function my class to make a pagination," /> conn, $sql); return mysqli_fetch_all($query, MYSQLI_ASSOC); }}$obj = new Mynews;?>display post: readAllarticles() as $art) { extract($art); ?> Now i want a function my class to make a pagination," />

OBJECT ORIENTED PHP: PAGING RESULT SETS

conn = mysqli_connect("localhost", "root", "", "mynews"); } public function readAllarticles() $sql = "SELECT * FROM articles WHERE status="publish""; $query = mysqli_query($this->conn, $sql); return mysqli_fetch_all($query, MYSQLI_ASSOC); }$obj = new Mynews;?>display post: readAllarticles() as $art) extract($art); ?>

Now i want a function my class to lớn make a pagination... và sorry for my bad eng.. :(


Bạn đang xem: Object oriented php: paging result sets

*

*

You use it:

data = array_slice($values,$param1,$per_page);for($x=1; $xdata;return $resultsValues;}// Sample Usage$pag = new Pagination();$data = array("Hello","Rex","Prosper","Adrivan","Hehe");$numbers = $pag->Paginate($data,2);$result = $pag->fetchResult();foreach($result as $r)echo "
I use this & it works for me

PHP

function pagination_one($webpage, $total_pages,$page) // Maximum number of link per page. If exceeded, google style pagination is generated $max_links = 6; $h=1; if($page>$max_links) $h=(($h+$page)-$max_links); if($page>=1) $max_link = $max_links+($page-1); if($max_links>$total_pages) $max_links=$total_pages+1; eđến "

Xem thêm: Kem Chống Nắng Nivea Có Tốt Không ? Kem Chống Nắng Nivea Có Tốt Không

"; if($page>"1") eđến " "; if($total_pages!=1) for ($i=$h;$i"; else eđến ""; if(($page >="1")&&($page!=$total_pages)) emang đến " "; eđến "
"; }function pagination_one($webpage, $total_pages,$page) // Maximum number of liên kết per page. If exceeded, google style pagination is generated $max_links = 6; $h=1; if($page>$max_links) $h=(($h+$page)-$max_links); if($page>=1) $max_liên kết = $max_links+($page-1); if($max_links>$total_pages) $max_links=$total_pages+1; emang đến "
"; if($page>"1") emang đến " "; if($total_pages!=1) for ($i=$h;$i"; else eđến ""; } if(($page >="1")&&($page!=$total_pages)) emang lại " "; emang lại "
"; }// get the pagenum. If it doesn"t exist, phối it lớn 1if(isset($_GET<"pagenum">) ? $page = $_GET<"pagenum">:$page = 1);// phối the number of entries lớn appear on the page$entries_per_page = 6; // total pages is rounded up lớn nearest integer$total_pages = ceil($getresult/$entries_per_page); // offset is used by Squốc lộ query in the LIMIT$offset = (($page * $entries_per_page) - $entries_per_page); $sql = "SELECT * FROM articles WHERE status="publish" LIMIT $offset,$entries_per_page";// bởi vì your query resultspagination_one("articles.php", $total_pages,$page);and CSS

.page_numbers width:100%; background:#fff9f0; overflow:hidden; position:relative; padding:50px 0;.page_numbers ul, .pagenums ul clear:left; float:left; list-style:none; margin:0; padding:0; position:relative; left:50%; text-align:center;.page_numbers ul li,.pagenums ul li display:block; float:left; list-style:none; margin:1px; padding:0; position:relative; right:50%; background: #a8a189; width:25px; .page_numbers ul li a, .pagenums ul li a display:block; background: #fff; border: 1px solid #a8a189; padding:3px 6px; text-decoration: none; color: #7a7564; font:bold 11px arial, verdana,sans-serif;.page_numbers li.current,.pagenums li.current width:50px; .page_numbers a.current, .page_numbers li a:hover,.pagenums a.current, .pagenums li a:hover background: #a8a189; color: #fff;