0

i have this so far:

<?php  
    $sql = "SELECT COUNT(id_noticia) FROM noticias, categorias, usuarios WHERE noticias.estado = 1 AND noticias.id_categoria = categorias.id_categoria AND categorias.estado = 1 AND noticias.id_usuario = usuarios.id_usuario AND noticias.id_categoria = '".$id_cat."'";  
    $rs_result = mysqli_query($con, $sql);
    $row = mysqli_fetch_row($rs_result);
    $total_records = $row[0];
    $total_pages = ceil($total_records / $limit);
    echo "<ul class='pagination'>";
        if($pag != '1'){
            $pagAnt = ($pag - 1);
            echo "<li><a href='valle/".$id_cat."/".$pagAnt."'><i class='fa fa-angle-double-left'></i></a></li>";
        }
        for ($i=1; $i <= $total_pages; $i++) {
            if($pag == $i){
                $pagLink .= "<li class='active'><a>".$i."</a></li>";
            }else{
                $pagLink .= "<li><a href='valle/".$id_cat."/".$i."'>".$i."</a></li>";  
            }
        };
        echo $pagLink;
         if($pag != $total_pages){
             $pagSig = ($pag + 1);
             echo "<li><a href='valle/".$id_cat."/".$pagSig."'><i class='fa fa-angle-double-right'></i></a></li>";
         }
         echo "</ul>";
?>  

and the output its like this:

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | infinite

The output that i want it's something like this:

1 | 2 | 3 | 4 | ,,, | 9

And if im in page 5 the output like this:

1 | ... | 5 | ... | 8

How can i do it?

  • Your code is likely vulnerable to [**SQL injection attacks**](https://en.wikipedia.org/wiki/SQL_injection). You should use [**mysqli**](https://secure.php.net/manual/en/mysqli.prepare.php) or [**PDO**](https://secure.php.net/manual/en/pdo.prepared-statements.php) prepared statements with bound parameters as described in [**this post**](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). – Alex Howansky Apr 25 '17 at 19:03
  • see this simple php sql paginator https://github.com/julekgwa/php_paginator – Junius L. Apr 25 '17 at 19:14

0 Answers0