You search for PHP paging, before that you need to understand what paging is. Result paging is something very simple.
We do a search in a certain table of the Database, and with the search result, we divide the number of records, by a specific number to display per page.
For example a total of 200 records, and we want to display 20 per page, so we have 200/20 = 10 pages. Simple, no? Well let’s go to the code then.
First connect to Mysql:
<?php
$conn = mysql_connect("host","usuario","senha");
$db = mysql_select_db("bancodedados");
?>
Now let’s create the SQL clause that must be executed:
<?php
$busca = "SELECT * FROM tabelax";
?>
Let’s get to work... Specify the total records to be displayed per page:
<?php
$total_reg = "10"; // número de registros por página
?>
If the page is not specified the "page" variable will be set to 1, this avoids displaying the beginning page 0:
<?php
$pagina=$_GET['pagina'];
if (!$pagina) {
$pc = "1";
} else {
$pc = $pagina;
}
?>
Let’s determine the initial value of the limited searches:
<?php
$inicio = $pc - 1;
$inicio = $inicio * $total_reg;
?>
Let’s select the data and display the pagination:
<?php
$limite = mysql_query("$busca LIMIT $inicio,$total_reg");
$todos = mysql_query("$busca");
$tr = mysql_num_rows($todos); // verifica o número total de registros
$tp = $tr / $total_reg; // verifica o número total de páginas
// vamos criar a visualização
while ($dados = mysql_fetch_array($limite)) {
$nome = $dados["nome"];
echo "Nome: $nome<br>";
}
// agora vamos criar os botões "Anterior e próximo"
$anterior = $pc -1;
$proximo = $pc +1;
if ($pc>1) {
echo " <a href='?pagina=$anterior'><- Anterior</a> ";
}
echo "|";
if ($pc<$tp) {
echo " <a href='?pagina=$proximo'>Próxima -></a>";
}
?>
Ready, our PHP pagination is created!
Read more in: PHP Pagination http://www.devmedia.com.br/paginacao-em-php/21972#ixzz3EL04G7wL
Source: http://www.devmedia.com.br/paginacao-em-php/21972
Search by pagination on the site, have a diversity of questions and answers on the subject.
– Bacco
People, I am reopening the question because it is possible to answer it without extending too much, as evidenced by Hiago’s answer below. Leandro, even so it is recommended to be more specific in your question. If you already have the site, it would be nice to have included in the question as you already do the complete listing of the news. So the staff has a starting point, understands what you already know, etc. Remembering yet that at any time you can [Edit] your questions to improve them. Thank you.
– bfavaretto