Pagination of results in php with page limit

0

I have a website that I need to display several images per page. I limited this view to 16 items per page, which resulted in 10 pages. Since the site will also appear in mobile , it will look strange if the page 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. I have tried to adapt some examples that I saw here, but without success.

<?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>';
            }


    }

?>
    
asked by anonymous 01.06.2017 / 23:46

0 answers