PHP - paginacion php

 
Vista:
sin imagen de perfil

paginacion php

Publicado por Brian (1 intervención) el 26/09/2017 13:25:23
hola, resulta que tengo este código para paginación, pero a pesar de mis intentos por resolverlos no encuentro el error, ya que no me salen los 10 resultados, sino que salen todos. Y si es cierto que me recoge las páginas que existen y me las muestra.
Si alguien me puede dar una solución sería de gran ayuda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<table class="table table-striped ">
    <thead>
        <tr>
            <th>CODIGO</th>
            <th>PRODUCTO</th>
            <th>ENVASE</th>
            <th>SECTOR</th>
            <th>SECCION</th>
            <th>TIPO EMPAQUETADO</th>
            <th>UNIDADES EMPAQUETADO</th>
            <th>PRECIO UNIDAD</th>
            <th>PRECIO</th>
        </tr>
    </thead>
    <tbody id="userData">
        <?php
            include 'DB.php';
            $consulta_noticias = "SELECT * FROM proveedores";
            $rs_noticias = mysqli_query($con, $consulta_noticias);
            $num_total_registros = mysqli_num_rows($rs_noticias);
            //Si hay registros
            if ($num_total_registros > 0) {
                //Limito la busqueda
                $TAMANO_PAGINA = 10;
                    $pagina = false;
 
                //examino la pagina a mostrar y el inicio del registro a mostrar
                    if (isset($_GET["pagina"]))
                        $pagina = $_GET["pagina"];
 
                if (!$pagina) {
                    $inicio = 0;
                    $pagina = 1;
                }
                else {
                    $inicio = ($pagina - 1) * $TAMANO_PAGINA;
                }
                //calculo el total de paginas
                $total_paginas = ceil($num_total_registros / $TAMANO_PAGINA);
            $db = new DB();
            $users = $db->getRows('proveedores',array('order_by'=>'codigo DESC'));
            if(!empty($users)){ $count = 0;
                foreach($users as $user){ $count++;
 
        ?>
        <tr>
            <td><?php echo $user['codigo']; ?></td>
            <td><?php echo $user['producto']; ?></td>
            <td><?php echo $user['envase']; ?></td>
            <td><?php echo $user['sector']; ?></td>
            <td><?php echo $user['seccion']; ?></td>
            <td><?php echo $user['tipoempaquetado']; ?></td>
            <td><?php echo $user['unidadesempaquetado']; ?></td>
            <td><?php echo $user['preciounidad']; ?></td>
            <td><?php echo $user['precio']; ?></td>
 
        </tr>
        <?php } }else{ ?>
        <tr><td colspan="5">No user(s) found...</td></tr>
        <?php } ?>
    </tbody>
</table>
 
<?php
 
    if ($total_paginas > 1) {
       if ($pagina != 1)
          echo '<a href="'.$url.'?pagina='.($pagina-1).'"><img src="images/izq.gif" border="0"></a>';
          for ($i=1;$i<=$total_paginas;$i++) {
             if ($pagina == $i)
                //si muestro el índice de la página actual, no coloco enlace
                echo $pagina;
             else
                //si el índice no corresponde con la página mostrada actualmente,
                //coloco el enlace para ir a esa página
                echo '  <a href="'.$url.'?pagina='.$i.'">'.$i.'</a>  ';
          }
          if ($pagina != $total_paginas)
             echo '<a href="'.$url.'?pagina='.($pagina+1).'"><img src="images/der.gif" border="0"></a>';
    }
}
?>
</div>
</div>
<!-- /#page-content-wrapper -->
 
</div>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder