Hello, I have a simple pager. The paginator works entering from its own page, but it turns out that the data that pages are loaded in a div through AJAX, then when trying to advance between the links of the pager shows me an error of Object not localized!.
I have attached code where I have the pager.
<div id="Cusuarios">
<table class="highlight responsive-table" id="Dusuarios">
<thead>
<tr>
<th>ID</th>
</tr>
</thead>
<tbody>
<?php
$pagActual = 1;
$regMostrar = 5;
if (array_key_exists('pg', $_GET)) { $pagActual = $_GET['pg']; }
$mysqli = mysqli_connect('localhost', 'root', '', 'paginador');
if ($mysqli->connect_errno) {
echo "Falló al conectar ".$mysqli->connect_errno;
exit();
}
$query = $mysqli->query("SELECT COUNT(*) as total FROM usuarios");
$total = "";
if ($query) {
while ($obj = $query->fetch_object()) { $total = $obj->total; }
}
$query->close();
unset($obj);
if ($total<$regMostrar) { $ultimaPag = 1; }
else { $ultimaPag = intval($total/$regMostrar); }
$segmento = $mysqli->query("SELECT * FROM usuarios LIMIT ".(($pagActual-1)*$regMostrar).", ".$regMostrar."");
if ($segmento) {
while ($fila = $segmento->fetch_object()) {
echo "<tr id='".$fila->id."'>";
echo "</tr>";
}
}
?>
</tbody>
</table>
</div>
<ul class="pagination">
<?php
echo "<li class='waves-effect'><a href='paginador.php?pg=".(1)."' title='Primera'>primera</a></li>";
for ($i=0; $i<$ultimaPag; $i++) {
echo "<li class='waves-effect "; if ($pagActual == $i+1) { echo "active"; }
echo "'><a href='paginador.php?pg=".($i+1)."'>".($i+1)."</a></li>";
}
echo "<li class='waves-effect'><a href='paginador.php?pg=".($ultimaPag)."' title='Última'>ultima</a></li>";
?>
</ul>
The AJAX call is made through a link.
$(document).ready(function(){
$(".cliente").click(function(event){
event.preventDefault();
$(".contenido").load("paginador.php");
});
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="menu">
<li>
<a href="#" class="btn-floating usuario">usuario</a>
</li>
</ul>
<div class="col l9 s12 contenido">
<h3>¡Hola!</h3>
</div>