Foros del Web » Programando para Internet » PHP »

Paginacion de juego de registros no muestra los siguientes resultados

Estas en el tema de Paginacion de juego de registros no muestra los siguientes resultados en el foro de PHP en Foros del Web. Hola, miren estoy tratando de hacer un buscador por medio de un list/menu que al seleccionar un dia por ej. "Lunes" muestre el rol de ...
  #1 (permalink)  
Antiguo 04/07/2012, 14:42
 
Fecha de Ingreso: mayo-2012
Ubicación: Distrito Federal
Mensajes: 49
Antigüedad: 11 años, 10 meses
Puntos: 9
Pregunta Paginacion de juego de registros no muestra los siguientes resultados

Hola, miren estoy tratando de hacer un buscador por medio de un list/menu que al seleccionar un dia por ej. "Lunes" muestre el rol de juegos de ese dia.

Todo funciona bien, muestra los resultados al seleccionar el dia; el problema es con el juego de paginacion de registros ya que cuando oprimo el boton de mostrar los siguientes resultados ya no muestra los demas y si le doy regresar se queda igual (sin mostrar nada).

Espero que me haya explicado bien, aqui les dejo el codigo para ver si me pueden ayudar. De antemano gracias:

Código:
<?php require_once('Connections/bd_sistema.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"];

$maxRows_mostrar_datos = 2;
$pageNum_mostrar_datos = 0;
if (isset($_GET['pageNum_mostrar_datos'])) {
  $pageNum_mostrar_datos = $_GET['pageNum_mostrar_datos'];
}
$startRow_mostrar_datos = $pageNum_mostrar_datos * $maxRows_mostrar_datos;

$colname_mostrar_datos = "-1";
if (isset($_POST['busqueda'])) {
  $colname_mostrar_datos = $_POST['busqueda'];
}
mysql_select_db($database_bd_sistema, $bd_sistema);
$query_mostrar_datos = sprintf("SELECT * FROM rol_de_juegos WHERE dia LIKE %s", GetSQLValueString("%" . $colname_mostrar_datos . "%", "text"));
$query_limit_mostrar_datos = sprintf("%s LIMIT %d, %d", $query_mostrar_datos, $startRow_mostrar_datos, $maxRows_mostrar_datos);
$mostrar_datos = mysql_query($query_limit_mostrar_datos, $bd_sistema) or die(mysql_error());
$row_mostrar_datos = mysql_fetch_assoc($mostrar_datos);

if (isset($_GET['totalRows_mostrar_datos'])) {
  $totalRows_mostrar_datos = $_GET['totalRows_mostrar_datos'];
} else {
  $all_mostrar_datos = mysql_query($query_mostrar_datos);
  $totalRows_mostrar_datos = mysql_num_rows($all_mostrar_datos);
}
$totalPages_mostrar_datos = ceil($totalRows_mostrar_datos/$maxRows_mostrar_datos)-1;

$queryString_mostrar_datos = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_mostrar_datos") == false && 
        stristr($param, "totalRows_mostrar_datos") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_mostrar_datos = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_mostrar_datos = sprintf("&totalRows_mostrar_datos=%d%s", $totalRows_mostrar_datos, $queryString_mostrar_datos);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <label>
    <select name="busqueda" id="busqueda">
      <option selected="selected">Elija un dia</option>
      <option>Lunes</option>
      <option>Martes</option>
      <option>Miercoles</option>
    </select>
  </label>
  <label>
    <input type="submit" name="btnBuscar" id="btnBuscar" value="Buscar" />
  </label>
</form>
<p>&nbsp;</p>
<table width="200" border="1">
  <tr>
    <td>DIA</td>
    <td>JORNADA</td>
    <td>PARTIDO</td>
    <td>FECHA</td>
    <td>HORA</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_mostrar_datos['dia']; ?></td>
      <td><?php echo $row_mostrar_datos['jornada']; ?></td>
      <td><?php echo $row_mostrar_datos['partido']; ?></td>
      <td><?php echo $row_mostrar_datos['facha']; ?></td>
      <td><?php echo $row_mostrar_datos['hora']; ?></td>
    </tr>
    <?php } while ($row_mostrar_datos = mysql_fetch_assoc($mostrar_datos)); ?>
</table>
<br />
<table border="0">
  <tr>
    <td><?php if ($pageNum_mostrar_datos > 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_mostrar_datos=%d%s", $currentPage, 0, $queryString_mostrar_datos); ?>"><img src="imagenes/First.gif" /></a>
        <?php } // Show if not first page ?></td>
    <td><?php if ($pageNum_mostrar_datos > 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_mostrar_datos=%d%s", $currentPage, max(0, $pageNum_mostrar_datos - 1), $queryString_mostrar_datos); ?>"><img src="imagenes/Previous.gif" /></a>
        <?php } // Show if not first page ?></td>
    <td><?php if ($pageNum_mostrar_datos < $totalPages_mostrar_datos) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_mostrar_datos=%d%s", $currentPage, min($totalPages_mostrar_datos, $pageNum_mostrar_datos + 1), $queryString_mostrar_datos); ?>"><img src="imagenes/Next.gif" /></a>
        <?php } // Show if not last page ?></td>
    <td><?php if ($pageNum_mostrar_datos < $totalPages_mostrar_datos) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_mostrar_datos=%d%s", $currentPage, $totalPages_mostrar_datos, $queryString_mostrar_datos); ?>"><img src="imagenes/Last.gif" /></a>
        <?php } // Show if not last page ?></td>
  </tr>
</table>
<br />
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($mostrar_datos);
?>
  #2 (permalink)  
Antiguo 04/07/2012, 19:04
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 7 meses
Puntos: 2237
Respuesta: Paginacion de juego de registros no muestra los siguientes resultados

El problema que veo es que primero obtienes busqueda desde $_POST y en la paginación, siendo enlaces, envías sólo el número de página y no incluyes lo que se va a buscar.

Te recomiendo que el formulario sea por método get y que también incluyas busqueda en los enlaces de paginación:

<a href="<?php printf("%s?busqueda=%s&amp;pageNum_mostrar_datos=%d%s", $currentPage, $colname_mostrar_datos, 0, $queryString_mostrar_datos); ?>"><img src="imagenes/First.gif" /></a>

Aunque habría que revisar como queda el HTML final, tengo mis dudas por como estás armando $queryString_mostrar_datos, pero ya afinarás esos detalles.
__________________
- León, Guanajuato
- GV-Foto
  #3 (permalink)  
Antiguo 05/07/2012, 10:01
 
Fecha de Ingreso: mayo-2012
Ubicación: Distrito Federal
Mensajes: 49
Antigüedad: 11 años, 10 meses
Puntos: 9
Respuesta: Paginacion de juego de registros no muestra los siguientes resultados

Hola Triby muchas gracias por tu respuesta y darme la pista de la solucion:

Lo que hice fue como me comentaste enviar el formulario por medio del metodo GET y la varialble colname tambien debe llevar el mismo metodo GET.

Y ahora si la paginacion funciona correctamente

Etiquetas: html, juego, muestra, mysql, paginacion, registro, registros, siguientes, sql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:19.