
Error de Paginación
Publicado por Sylver (5 intervenciones) el 21/01/2016 04:14:53
Tengo un error en la paginación por ajax con un botón de mostrar más sólo cuando se realiza un filtro, este es mi código en el index principal.
Mi clase que pagina busca es esta: "classUsuarios.php"
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
88
89
90
91
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<!--<link href="ui/themes/base/jquery.ui.all.css" rel="stylesheet" type="text/css" media="screen" />-->
<!--<script src="js/jquery-1.6.2.js"></script>-->
<!--<script src="ui/jquery.ui.core.js"></script>
<script src="ui/jquery.ui.datepicker.js"></script>
<script src="ui/jquery.ui.datepicker-es.js"></script>-->
<style>
.mostrar-mas{
text-align: center;
background-color: #D9EDF7;
border: 1px solid #BCE8F1;
}
.mostrar-mas a{
display: block;
padding: 5px 20px;
}
</style>
<script>
$(function(){
/*var ajaxMot;
var ajax;
var pagina_actual=0;
var loading = false;
var old_scroll = 0;
var total_pages = 1;*/
var paginacion = $('.pagination');
//ocultar la paginacion
//paginacion.hide();
//Agregar link de mostrar más
paginacion.after('<div class="mostrar-mas"><a href="#">Mostrar Más</a></div>');
//Buscar nuevos resultados
$('.mostrar-mas a').on('click', function(e){
e.preventDefault();
$.ajax({
type: 'GET',
url: $('.pagination li.next a').attr('href'),
//url: $("'prueba.php?q=m'+posicion").attr('href'),
//data('posicion=valor'),
success: function(html){
//alert(html);
//Obtener paises nuevos
var nuevosPaises = $(html).find('table tbody'),
nuevaPaginacion = $(html).find('.pagination'),
tabla = $('table');
//Agregar paises a la tabla
tabla.find('tbody').append(nuevosPaises.html());
//Actualizar link de "Mostra mas"
tabla.after(nuevaPaginacion.hide());
}
});
});
});
</script>
</head>
<body>
<section class="container col-md-6 col-md-offset-3">
<form id="frmpaises" action="prueba.php" method="GET">
<label>Buscador</label>
<input type="text" name="q" value="">
<!---div class="mostrar-mas"><a href="#">Mostrar Más 1</a></div>-->
<input type="submit" value="Buscar">
</form>
<?php
require_once 'classUsuarios.php';
$valor = (filter_input(INPUT_GET, 'q'));
$usuarios = new Usuarios();
$usuarios->setValor($valor);
$usuarios->mostrar();
?>
</section>
</body>
</html>
Mi clase que pagina busca es esta: "classUsuarios.php"
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
88
89
90
91
92
93
94
95
<?php
class Usuarios {
private $country_id;
private $iso2;
private $short_name;
private $long_name;
private $valor;
function __construct() {}
public function getCountry_id(){ return $this->country_id; }
public function getIso2(){ return $this->iso2; }
public function getShort_name(){ return $this->short_name; }
public function getLong_name(){ return $this->long_name; }
public function setValor($valor){ $this->valor = $valor; }
public function mostrar(){
require_once 'libs/ez_sql_core.php';
require_once 'libs/ez_sql_mysql.php';
require_once 'libs/Zebra_Pagination.php';
$bd = new ezSQL_mysql('root','','prueba');
$sqltotal = "SELECT * FROM paises";
if (isset($this->valor)) {
$sqltotal .= " WHERE short_name LIKE '".$this->valor."%'";
}
$total_registros = $bd->query($sqltotal);
/*$total = $bd->query($sqltotal);
$total_registros = mysqli_num_rows($total);*/
$resultados = 10;
$paginacion = new Zebra_Pagination();
$paginacion->records($total_registros);
$paginacion->records_per_page($resultados);
$paginacion->padding(false);
$sql = "SELECT * from paises ";
if (isset($this->valor)) {
$sql .= "WHERE short_name LIKE '".$this->valor."%'";
}
$sql .= " LIMIT ".(($paginacion->get_page()-1) * $resultados).','.$resultados;
/*$base = $bd->query($sql);
echo "<table class='table table-hover'><tr><th>ID</th><th>ISO2</th><th>NOMBRE CORTO</th><th>NOMBRE LARGO</th></tr>";
while ($row = $base->fetch_object()) {
echo "<tr><td>".$row->country_id."</td><td>".$row->iso2."</td><td>".$row->short_name."</td><td>".$row->long_name."</td></tr>";
}
echo "</tables>";*/
$registros = $bd->get_results($sql);
echo "<table class='table table-hover'>
<thead>
<tr>
<th>ID</th>
<th>ISO 2</th>
<th>NOMBRE CORTO</th>
<th>NOMBRE LARGO</th>
</tr>
</thead>
<tbody>";
foreach ($registros as $registro):
echo "<tr>
<th>".$registro->country_id."</th>
<th>".$registro->iso2."</th>
<th>".$registro->short_name."</th>
<th>".$registro->long_name."</th>
</tr>";
endforeach;
//echo "<span style='display:none;'>$cout;</span>";
echo "</tbody>
</table>";
$posicion = ((($paginacion->get_page()-1)*$resultados)/$resultados)+1;
//echo $posicion;
//echo $_GET["posicion"];
$paginacion->render();
//echo '<div class="mostrar-mas"><a href="#">Mostrar Más</a></div>';
}
}
?>
- Paginacion.rar(150,1 KB)
Valora esta pregunta


0