Recabamos por todo el mundo online para mostrarte la solución para tu duda, si tienes alguna inquietud deja tu pregunta y te respondemos porque estamos para servirte.
Ejemplo 1: paginación html php
<html><head><title>Paginationtitle><linkrel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">script>head><body>if(isset($_GET['pageno']))$pageno=$_GET['pageno'];else$pageno=1;$no_of_records_per_page=10;$offset=($pageno-1)*$no_of_records_per_page;$conn=mysqli_connect("localhost","my_user","my_password","my_db");// Check connectionif(mysqli_connect_errno())echo"Failed to connect to MySQL: ".mysqli_connect_error();die();$total_pages_sql="SELECT COUNT(*) FROM table";$result=mysqli_query($conn,$total_pages_sql);$total_rows=mysqli_fetch_array($result)[0];$total_pages=ceil($total_rows/$no_of_records_per_page);$sql="SELECT * FROM table LIMIT $offset, $no_of_records_per_page";$res_data=mysqli_query($conn,$sql);while($row=mysqli_fetch_array($res_data))//here goes the datamysqli_close($conn);?><ulclass="pagination"><li><ahref="?pageno=1">Firsta>li><liclass="if($pageno<=1)echo'disabled';?>"><ahref="if($pageno<=1)echo'#';elseecho"?pageno=".($pageno-1);?>">Preva>li><liclass="if($pageno>=$total_pages)echo'disabled';?>"><ahref="if($pageno>=$total_pages)echo'#';elseecho"?pageno=".($pageno+1);?>">Nexta>li><li><ahref="?pageno=echo$total_pages;?>">Lasta>li>ul>body>html>
Ejemplo 2: paginación en php
try// Find out how many items are in the table$total=$dbh->query('
SELECT
COUNT(*)
FROM
table
')->fetchColumn();// How many items to list per page$limit=20;// How many pages will there be$pages=ceil($total/$limit);// What page are we currently on?$page=min($pages,filter_input(INPUT_GET,'page',FILTER_VALIDATE_INT,array('options'=>array('default'=>1,'min_range'=>1,),)));// Calculate the offset for the query$offset=($page-1)*$limit;// Some information to display to the user$start=$offset+1;$end=min(($offset+$limit),$total);// The "back" link$prevlink=($page>1)?'« .($page-1).'" title="Previous page">‹':'« ‹';// The "forward" link$nextlink=($page<$pages)?'.($page+1).'" title="Next page">› .$pages.'" title="Last page">»':'› »';// Display the paging informationecho'',$prevlink,' Page ',$page,' of ',$pages,' pages, displaying ',$start,'-',$end,' of ',$total,' results ',$nextlink,'
';// Prepare the paged query$stmt=$dbh->prepare('
SELECT
*
FROM
table
ORDER BY
name
LIMIT
:limit
OFFSET
:offset
');// Bind the query params$stmt->bindParam(':limit',$limit,PDO::PARAM_INT);$stmt->bindParam(':offset',$offset,PDO::PARAM_INT);$stmt->execute();// Do we have any results?if($stmt->rowCount()>0)// Define how we want to fetch the results$stmt->setFetchMode(PDO::FETCH_ASSOC);$iterator=newIteratorIterator($stmt);// Display the resultsforeach($iteratoras$row)echo''
,$row['name'],' ';elseecho'No results could be displayed.
';catch(Exception$e)echo''
,$e->getMessage(),'';
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)