concatenar paginacion php mysql ajax
Publicado por José (3 intervenciones) el 10/09/2019 21:40:25
Saludos comunidad de lwp, solicito de su ayuda para solucionar un problema que tengo con concatenar la paginación de una tabla que tengo en MySQL y que utiliza ajax para la consulta y mostrar el resultado en una pagina html.
Cabe mencionar que por ahora ya me muestra los resultados de la consulta a la base de datos. También me parece la paginación, aunque me la muestra en buscar.php, y requiero que me la concatene y envie a consulta.html via ajax. Aqui es donde estoy trabado. Presiento que la clave para resolver esto esta en la siguiente linea:
ya que esto esta enlazado con
para el link de Anterior y para el link de Siguiente:
Pero es aquí donde ya me nuble y no se como resolverlo.
Les comparto todo el archivo buscar.php esperando compartir la solución y me puedan ayudar.
Cabe mencionar que por ahora ya me muestra los resultados de la consulta a la base de datos. También me parece la paginación, aunque me la muestra en buscar.php, y requiero que me la concatene y envie a consulta.html via ajax. Aqui es donde estoy trabado. Presiento que la clave para resolver esto esta en la siguiente linea:
1
$currentPage = $_SERVER["PHP_SELF"];
ya que esto esta enlazado con
1
<a href='".sprintf("%s?pageNum=%d%s", $currentPage, max(0, $pageNum - 1), $queryString)."'>Anterior</a>
para el link de Anterior y para el link de Siguiente:
1
<a href='".sprintf("%s?pageNum=%d%s", $currentPage, min($totalPages, $pageNum + 1), $queryString)."'>Siguiente</a>
Pero es aquí donde ya me nuble y no se como resolverlo.
Les comparto todo el archivo buscar.php esperando compartir la solución y me puedan ayudar.
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php require_once('Connections/conexion.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$currentPage = $_SERVER["PHP_SELF"]; //Aquí
$maxRows= 7;
$pageNum= 0;
if (isset($_GET['pageNum'])) {
$pageNum = $_GET['pageNum'];
}
$startRow = $pageNum * $maxRows;
$salida="";
mysql_select_db($database_conexion, $conexion);
$query = "SELECT clave, producto, piezas, lote, caducidad, ubicacion, datediff(caducidad, curdate()) as 'dias' FROM existencias ORDER BY clave";
if(isset($_POST['consulta'])){
$q=mysql_real_escape_string($_POST['consulta']);
$query="SELECT clave, producto, piezas, lote, caducidad, ubicacion, datediff(caducidad, curdate()) as 'dias' FROM existencias WHERE clave LIKE '%".$q."%' OR producto LIKE '%".$q."%' ORDER BY clave";
}
$query_limit = sprintf("%s LIMIT %d, %d", $query, $startRow, $maxRows);
$res = mysql_query($query_limit);
if (isset($_GET['totalrows'])) {
$totalrows = $_GET['totalrows'];
} else {
$all= mysql_query($query);
$totalrows = mysql_num_rows($all);
}
$totalPages = ceil($totalrows/$maxRows)-1;
$queryString = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum") == false &&
stristr($param, "totalrows") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString = sprintf("&totalrows=%d%s", $totalrows, $queryString);
if ($totalrows > 0) {
$salida.="<table>
<thead>
<tr>
<th>CLAVE</th>
<th>PRODUCTO</th>
<th>PIEZAS</th>
<th>LOTE</th>
<th>CADUCIDAD</th>
<th>UBICACION</th>
<th>DIAS A CADUCAR</th>
</tr>
</thead>
<tbody>";
while ($row = mysql_fetch_assoc($res)) {
$salida.="<tr>
<td>".$row['clave']."</td>
<td>".$row['producto']."</td>
<td>".$row['piezas']."</td>
<td>".$row['lote']."</td>
<td>".$row['caducidad']."</td>
<td>".$row['ubicacion']."</td>
<td>".$row['dias']."</td>
</tr>";
}
$salida.="</tbody></table><table width='33%' border='1'>
<tr>
<td align='left'><a href='".sprintf("%s?pageNum=%d%s", $currentPage, max(0, $pageNum - 1), $queryString)."'>Anterior</a></td>
<td align='center'>Registros ".($startRow + 1)." a ".min($startRow + $maxRows, $totalrows)." de ".$totalrows."</td>
<td align='right'><a href='".sprintf("%s?pageNum=%d%s", $currentPage, min($totalPages, $pageNum + 1), $queryString)."'>Siguiente</a></td>
</tr></table>";
}else{
$salida.="NO HAY DATOS :(";
}
echo $salida;
mysql_free_result($res);
?>
Valora esta pregunta


0