0
I’m trying to page by arrow, using ajax, but I’m not getting it...
Normal page I got (which is showing the numbers) but with arrow, I’m not getting.
jQuery:
var paginacao = {
iniciar: function(pagina){
$.ajax({
type: "POST",
url: "paginacao.php?pagina=" + pagina,
success: function (result) {
$('.all').html(result);
}
});
}
}
$(document).ready(function(){
paginacao.iniciar(1);
});
PHP:
<?php
include '../assets/app/config.php';
$conexao = new Conexao($config);
$pagina = (isset($_GET['pagina'])) ? $_GET['pagina'] : 1;
$sqlPaginacao = $conexao->conectar()->query("SELECT * FROM noticias"); //Pega resultado geral
$total = $sqlPaginacao->num_rows; // Conta os registros gerais
$qtd = 1; // Quantidade exibida por página
$paginas = ceil($total / $qtd); //Cálculo de quantas páginas vai dar
$inicio = ($qtd * $pagina) - $qtd; //Mostra o inicio
$sql = $conexao->conectar()->query("SELECT * FROM noticias LIMIT $inicio, $qtd"); //Pega resultado real
while($mostra = $sql->fetch_assoc()) {
echo "<article class='news'>{$mostra["titulo"]}</article>";
}
?>
HTML:
<?php
include '../assets/app/config.php';
$conexao = new Conexao($config);
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.arrow {
height: 20px;
width: 20px;
border: 1px solid #000;
display: -webkit-flex;
display: -moz-flex;
display: -ms-flex;
display: -o-flex;
display: flex;
justify-content: center;
float: left;
margin: 5px 5px;
cursor: pointer;
}
.arrow.disabled { opacity: 0.5; cursor: default; }
</style>
</head>
<body>
<div class="all">
</div>
<div class="arrow back disabled"><</div> <div class="arrow next">></div>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="script.js"></script>
</body>
</html>
I don’t understand what arrows?
– Wees Smith
This code is a little incomplete, I suggest bringing more details mainly of your html where in fact it is presented the pagination.
– André Lins
Precisely, I do not know how to continue the codes, I put HTML, to see if it is clearer.
– Renan