Paginacion with only result

0

I am trying to integrate a page that I had previously done, in fact I have it in a similar project and it works perfectly, for some reason in this part it only shows me the number 1 (a single page)

this is my paging code:

<?php $numero_paginas = numero_paginas($post_config['post_por_pagina'], $conexion); ?>

<section class="paginacion">
    <ul>
        <?php if (pagina_actual() === 1): ?>
            <li class="disabled">&laquo;</li>
        <?php else: ?>
            <li><a href="candidatos.php?p=<?php echo pagina_actual() - 1 ?>">&laquo;</a></li>
        <?php endif; ?>

        <?php for($i = 1; $i <= $numero_paginas; $i++): ?>
            <?php if (pagina_actual() === $i): ?>
                <li class="active">
                    <?php echo $i; ?>
                </li>
            <?php else: ?>
                <li><a href="candidatos.php?p=<?php echo $i; ?>"><?php echo $i; ?></a></li>
            <?php endif; ?>

        <?php endfor; ?>

        <?php if(pagina_actual() == $numero_paginas): ?>
            <li class="disabled">&raquo;</li>
        <?php else: ?>
            <li><a href="candidatos.php?p=<?php echo pagina_actual() + 1; ?>">&raquo;</a></li>
        <?php endif; ?>
    </ul>
</section>

the variable $numero_paginas I have in a file of functions, whose function is this:

function pagina_actual(){
    return isset($_GET['p']) ? (int)$_GET['p'] : 1;
}

function obtener_post($post_por_pagina, $conexion){
    $inicio = (pagina_actual() > 1) ? pagina_actual() * $post_por_pagina - $post_por_pagina : 0;
    $sentencia = $conexion->prepare("SELECT SQL_CALC_FOUND_ROWS * FROM userslog LIMIT $inicio, $post_por_pagina");
    $sentencia->execute();
    return $sentencia->fetchAll();
}

function numero_paginas($post_por_pagina, $conexion){
    $total_post = $conexion->prepare('SELECT FOUND_ROWS() as total');
    $total_post->execute();
    $total_post = $total_post->fetch()['total'];

    $numero_paginas = ceil($total_post / $post_por_pagina);
    return $numero_paginas;
}

and variable $post_por_pagina comes from a file called config in which it is indicated the post it will have per page:

$post_config = array(
    'post_por_pagina' => 1,
);

For some reason, it only shows me a single page

Could you help me know what I'm doing wrong or what I'm missing? I've broken my head trying to find the error and I have not got it

    
asked by Cesar Gutierrez Davalos 26.06.2017 в 03:57
source

0 answers