Number of pages in php page

Asked

Viewed 197 times

1

I have a page in PHP where I did the paging that is working perfectly, but I noticed that the screen is getting full of links with the numbering of the pages.

Currently I present only 3 results to each page. They would help me to limit the number of links of pagination?

I tried to do this limit, but always the page increases a number to +. I already managed to limit at the beginning, when I move to the next page the number of links increases to infinity!

Follows the code:

<?php
}
//PAGINAÇAO
if ($registros_ > 3) {
//Verificar a pagina anterior e posterior

	
	$max_links = 8;
	
	$links_laterais = ceil($max_links / 2);
	
	$pagina_anterior = $pagina - $links_laterais;
    $pagina_posterior = $pagina + $links_laterais;
	
    print "<div class='container'>
<div>
				<ul class='pagination'>
					<li>";
    if ($pagina_anterior > 0) {
        print "<a href='pesquisas.php?pagina=$pagina_anterior&tipo=$tipo&seletor=$seletor&filtro=$filtro' aria-label='Previous'>
                                <span aria-hidden='true'>&laquo;</span>
                            </a>";
    } else {
        print "<span aria-hidden='true'>&laquo;</span>";
    }
    print "</li>";
//Apresentar a paginacao

    for ($i = $pagina_anterior; $i < $pagina_posterior; $i++) {
	    if ($i >=1){ 
        print"<li><a href='pesquisas.php?pagina=$i&tipo=$tipo&seletor=$seletor&filtro=$filtro'>$i</a></li>";
    }
	}
	
    print "<li>";
    if ($pagina_posterior <= $num_pagina) {
        print " <a href='pesquisas.php?pagina=$pagina_posterior&tipo=$tipo&seletor=$seletor&filtro=$filtro' aria-label='Previous'>
            <span aria-hidden='true''>&raquo;</span>
        </a>";
    } else {
        print "<span aria-hidden='true'>&raquo;</span>";
    }
    print "</div></div>";
}
//F

I managed to solve my problem! Follow the code for those who have the same difficulty.

<?php
}
//PAGINAÇAO
if ($registros_ > 3) {
//Verificar a pagina anterior e posterior

	
	$max_links = 6;
	
	$links_laterais = ceil($max_links / 3);
	
	$pagina_anterior = $pagina - $links_laterais;
    $pagina_posterior = $pagina + $links_laterais;
	
    print "<div class='container'>
<div>
				<ul class='pagination'>
					<li>";
    if ($pagina_anterior > 0) {
        print "<a href='pesquisas.php?pagina=$pagina_anterior&tipo=$tipo&seletor=$seletor&filtro=$filtro' aria-label='Previous'>
                                <span aria-hidden='true'>&laquo;</span>
                            </a>";
    } else {
        print "<span aria-hidden='true'>&laquo;</span>";
    }
    print "</li>";
//Apresentar a paginacao

    for ($i = $pagina_anterior; $i < $pagina_posterior; $i++) {
	    if (($i >=1) && ($i <= $num_pagina)){ 
        print"<li><a href='pesquisas.php?pagina=$i&tipo=$tipo&seletor=$seletor&filtro=$filtro'>$i</a></li>";
    }
	}
	
    print "<li>";
    if ($pagina_posterior <= $num_pagina) {
        print " <a href='pesquisas.php?pagina=$pagina_posterior&tipo=$tipo&seletor=$seletor&filtro=$filtro' aria-label='Previous'>
            <span aria-hidden='true''>&raquo;</span>
        </a>";
    } else {
        print "<span aria-hidden='true'>&raquo;</span>";
    }
    print "</div></div>";
}
//FIM PAGINAÇAO
?>

  • You are opening many *tags, but you are not closing them. $num_pagina is getting what value?

  • Opa amigo, $quantidade_pg = 3; / $num_pagina = Ceil($registros_/$quantidade_pg);

  • Ever tried to replace $limite + 1 for $limite? Ps.: Avoid using the Snippet, it does not work with PHP.

  • I’ve tried it and it didn’t work it always goes beyond

  • Put the solution you found as an answer and then you can accept it

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.