-1
I need to make the pagination of my page, I already did once, but I had the queries on the screen and I could apply LIMIT, but in this other project the queries are in another file and the results come via ajax, as I should make the pagination in these cases?
<?php
session_start();
if(!isset($_SESSION['UsuarioLog'])){
header("location: login.php");
session_destroy();
}
if(isset($_GET['deslogar'])){
session_destroy();
header('Location: login.php');
}
include("conexao.php");
include("topo.php");
?>
<script>
$(document).ready(function() {
$(function(){
$("[class='formFilter']").submit();
})
$(".formFilter").on("submit", function(event){
$.ajax ({
method: "POST",
url: "processa-lista-tarefas.php",
data: new FormData(this),
contentType: false,
processData: false,
//beforeSend: function () {
//$("#grid").html("<img src='img/carregando.gif'>");
//},
success: function (response){
$('#grid').html(response);
$("#grid").hide().html(response).fadeIn('fast');
}
})
event.preventDefault();
})
})
</script>
<div class="container">
<div id="pagina">
<h3 >Lista de Tarefas</h3>
</div>
<hr>
<?php
if(isset($_SESSION['msg'])){
echo "<div id='mensagem' class='container'>".$_SESSION['msg']."</div>";
unset($_SESSION['msg']);
}
?>
<div class="container" name="pesuqisaNome">
<form method="POST" class='formFilter' id="margemInferior">
<div class="row">
<div class="col">
<label for="inputText">Solicitante</label>
<input type="text" class="form-control" placeholder="Nome do solicitante" value="<?php echo "$solicitante"?>" name="solicitante">
</div>
<div class="col">
<label for="inputSelect">Prioridade</label>
<select name= "prioridade" class="form-control" id="exampleFormControlSelect1">
<option value="" >Todos</option>
<option style="color: #28a745;" value="Baixa" <?php if ($prioridade == 'Baixa'){ echo "selected"; }; ?>>Baixa</option>
<option style="color: #ffc107;" value="Média" <?php if ($prioridade == 'Média'){ echo "selected"; }; ?>>Média</option>
<option style="color: #dc3545;" value="Alta" <?php if ($prioridade == 'Alta'){ echo "selected"; }; ?>>Alta</option>
</select>
</div>
<div class="col">
<label for="inputSelect">Status</label>
<select name= "status" class="form-control" id="exampleFormControlSelect1">
<option value="" >Todos</option>
<option value="Em processo de avaliação"<?php if ($status == 'Em processo de avaliação'){ echo "selected"; }; ?>>Em processo de avaliação</option>
<option value="Aprovado"<?php if ($status == 'Aprovado'){ echo "selected"; }; ?> >Aprovado</option>
<option value="Iniciado"<?php if ($status == 'Iniciado'){ echo "selected"; }; ?> >Iniciado</option>
<option value="Concluído" <?php if ($status == 'Concluído'){ echo "selected"; }; ?>>Concluído</option>
</select>
</div>
<div class="col-2">
<label for="inputSubmit"><br></label>
<input class="btn btn-primary btn-block" type="submit" value="Pesquisar">
</div>
</div>
</form>
</div>
<div id="grid" class="container">
</div>
<nav aria-label="Navegação de página exemplo">
<ul class="pagination justify-content-center">
<li class="page-item"><a class="page-link" href="#">Anterior</a></li>
<li class="page-item"><a class="page-link" href="lista.php?pagina=1">1</a></li>
<li class="page-item"><a class="page-link" href="lista.php?pagina=2">2</a></li>
<li class="page-item"><a class="page-link" href="lista.php?pagina=3">3</a></li>
<li class="page-item"><a class="page-link" href="#">Próximo</a></li>
</ul>
</nav>
</div>
<?php include("rodape.php");?>
this is the Cod of my main page that presents the data
<?php
include("conexao.php");
if (isset($_POST ['status'])){
$prioridade = $_POST ['prioridade'];
$solicitante = $_POST ['solicitante'];
$status = $_POST ['status'];
$consulta = "SELECT * FROM listademandas WHERE 1=1";
if($prioridade !=""){
$consulta = $consulta." AND prioridade= '$prioridade'";
};
if($solicitante !=""){
$consulta = $consulta." AND solicitante LIKE '%$solicitante%'";
};
if($status !="" ){
$consulta = $consulta." AND status_demanda= '$status'";
};
}else{
$consulta = "SELECT * FROM listademandas";
};
if($consulta != ''){
$conDb = mysqli_query($conn, $consulta);
echo ($paginaAtual);
$response = '<table class="table table-hover">
<thead>
<tr>
<th scope="col">Solicitação nº</th>
<th scope="col">Solicitante</th>
<th scope="col">Empresa</th>
<th scope="col">Tipo de solicitação</th>
<th scope="col">Solicitação</th>
<th scope="col">Prioridade</th>
<th scope="col">Status</th>
<th scope="col">Data da solicitação</th>
<th scope="col">Data da conclusão</th>
<th scope="col">Ações</th>
</tr>
</thead>';
while($dado = $conDb -> fetch_array()){
$response= $response.'<tbody> <tr>
<td>'.$dado["id"].'</td>
<td>'.$dado["solicitante"].' </td>
<td>'.$dado["empresa"].' </td>
<td>'.$dado["tipo"].' </td>
<td>'.$dado["solicitacao"].'</td>
<td>'.$dado["prioridade"].'</td>
<td>'.$dado["status_demanda"].' </td>
<td>'. date("d/m/Y", strtotime($dado["criacao"])).'</td>
<td>'. date("d/m/Y", strtotime($dado["edicao"])).'</td>
<td><a href="edita-tarefas.php?id='. $dado["id"] .'">Editar</a>
<a href="processa-exclusao-tarefas.php?id='. $dado["id"] .'" data-confirm="Tem certeza que deseja excluir o item selecionado?" >Excluir</a>
</td>
';
}
$response = $response.'
</tbody>
</table>
<script src="js/personalizado.js"></script>
';
}
echo $response;
?>
this is the code where I receive the data from ajax and do the queries, as I should mount the pagination?
Important [Dit] to post and replace the code with a [mcve] of the problem, with a description of the punctual difficulty to proceed with what you want. To understand what kind of question serves the site and, consequently, avoid closures and negativities worth reading What is the Stack Overflow and the Stack Overflow Survival Guide (summarized) in Portuguese.
– Bacco