Pagination of results in php with page limit

Asked

Viewed 166 times

0

I have a website which I need to display several images per page. I limited this display to 16 items per page, which resulted in 10 pages. As the site will also be displayed on mobile, It will be strange if the pagination exceeds 10 pages, and I would like it to be limited to only 10 and the user would click the arrow to go to the eleventh page. I’ve tried to adapt some examples I’ve seen around here, but to no avail.

<?php

$connection = mysqli_connect("localhost", "root", "", "countries");

$q1 = mysqli_query($connection, "SELECT * FROM countrie");

$count = mysqli_num_rows($q1);


$rowsperpage = 5;

$page = $_REQUEST['p'];

if( $page == 0 or $page == ''){
    $page = 1;
}

$page = $page - 1;

$p = $page * $rowsperpage;

$query = "SELECT * FROM countrie limit ".$p." , " .$rowsperpage;



$run = mysqli_query($connection, $query);

while( $rs = mysqli_fetch_array($run) ){

        echo $rs['id'].'->' .$rs['country_name'].' <br/>';
}


    if( $_REQUEST['p'] > 1){
    $prev_page = $_REQUEST['p'] - 1;

echo '<span style="cursor:pointer;" onclick="LoadData('.$prev_page.')">Back</span>';
}

    $check = $p + $rowsperpage;

    if( $count > $check){
    $next_page = $_REQUEST['p']+1;
echo '<span style="cursor:pointer;" onclick="LoadData('.$next_page.')">Next</span>';
}


    $limit = $count / $rowsperpage;

    $limit = ceil($limit);

    echo '</br></br>';
    for( $i=1; $i<=$limit; $i++ ){

        if( $i==$_REQUEST['p']){
            echo '<strong>' .$i.'<strong>';
            }
            else{
                echo '<span style="cursor:pointer;" onclick="LoadData('.$i.')">'.$i.'</span>';
            }


    }

?>
  • What you want is to display the links of the pages, type: [<] 3 4 5 6 7 [>]? In this case, it should be limited to 10 links only?

  • related https://answall.com/questions/200830/pagina%C3%A7%C3%A3o-de-resultados/200843#200843

  • yes, exactly, and from the first tenth onwards would be accessible by the arrow

No answers

Browser other questions tagged

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