Ayuda con paginacion, libreria Zebra Pagination
Publicado por Jhons (2 intervenciones) el 01/11/2019 20:06:04
Buenas tardes estimados , tengo una duda llevo días buscando como poder paginar paginas, hoy logre conseguir algo con esta librería pero al momento de cambiar de pagina me falla, les adjunto el código o si alguien sabe una buena manera de paginar se lo agradecería demasiado, son alrededor de 7000 registros, cabe destacar que el buscador.php lo ejecuto de un home que tiene el scrip para cargarlo dentro de un content.
buscador.php
mediciones.php
buscador.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
<?php
$mysqli = new mysqli('####', '####', '####', '####');
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<script src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
var consulta;
$("#raspberry").focus();
$("#raspberry").keyup(function(e){
consulta = $("#raspberry").val();
$.ajax({
type: "POST",
url: "../####/####/mediciones.php",
data: "b="+consulta,
dataType: "html",
beforeSend: function(){
$("#resultado").html("<p align='center'><img src='ajax-loader.gif' /></p>");
},
error: function(){
alert("error petición ajax");
},
success: function(data){
$("#resultado").empty();
$("#resultado").append(data);
}
});
});
});
</script>
</head>
<body>
<p>Filtrar mediciones (Seleccione Terminal): </p>
<hr>
<select id="raspberry" size="2" >
<?php
$query = $mysqli -> query ("SELECT DISTINCT serial_estacion FROM mediciones");
while ($valores = mysqli_fetch_array($query)) {
echo '<option value="'.$valores[serial_estacion].'">'.$valores[serial_estacion].'</option>';
}
?>
</select>
<div id="resultado"></div>
</body>
</html>
mediciones.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
96
97
98
99
100
101
102
103
104
105
<?php
require_once("Zebra_Pagination.php")
?>
<?php
$buscar = $_POST['b'];
if(!empty($buscar)) {
buscar($buscar);
}
function buscar($b) {
$mysqli = new mysqli("####", "####","####","####");
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$query="SELECT fecha,hora,sensor1 ,sensor2,id FROM mediciones WHERE serial_estacion='".$b."' order by id DESC";
$result = $mysqli->query($query);
$total_registros = $result->num_rows;
$resultados_pagina = 5;
$pagination = new Zebra_Pagination();
$pagination->records($total_registros);
$pagination->records_per_page($resultados_pagina);
$registro_actual = ($pagination->get_page() -1) * $resultados_pagina;
$query = "SELECT fecha,hora,sensor1 ,sensor2,id FROM mediciones WHERE serial_estacion='".$b."' order by id DESC LIMIT $registro_actual, $resultados_pagina";
$resultado = $mysqli->query($query);
//$contar= $result->num_rows;
//if($resultado == 0){
// echo "No se han encontrado resultados para '<b>".$b."</b>'.";
//}else{
while($row = $resultado->fetch_array(MYSQLI_ASSOC))
{
$fecha = $row['fecha'];
$hora = $row['hora'];
$sensor1 = $row['sensor1'];
$sensor2 = $row['sensor2'];
$fecha=utf8_encode($fecha);
$hora=utf8_encode($hora);
$sensor1=utf8_encode($sensor1);
$sensor2=utf8_encode($sensor2);
echo"
<div class='col-md-8 col-md-offset-2'>
<table class='table table-striped table-hover'>
<thead>
<tr>
<th width='10px'>Fecha</th>
<th>Hora</th>
<th>Sensor 1 Nivel</th>
<th>Sensor 2 Nivel</th>
<th scope='col'>Ver</th>
<th scope='col'>Editar</th>
<th scope='col'>Eliminar</th>
</tr>
</thead>
<tbody>
<tr>
<td>".$fecha."</td>
<td>".$hora."</td>
<td>".$sensor1."</td>
<td>".$sensor2."</td>
<td width='10px'><a href='#' class='btn btn-outline-success'>
Ver
</a></td>
<td width='10px'><a href='#' class='btn btn-outline-primary'>
Editar
</a></td>
<td width='10px'>
<button class='btn btn-outline-danger'>
Eliminar
</button>
</td>
</tr>
</tbody>
</table>
</div>
";
}
$pagination->render();
//}
}
?>
Valora esta pregunta


0