Ver Mensaje Individual
  #22 (permalink)  
Antiguo 06/02/2013, 08:53
Avatar de jandrogdz
jandrogdz
 
Fecha de Ingreso: julio-2012
Ubicación: public $Guadalajara
Mensajes: 397
Antigüedad: 11 años, 10 meses
Puntos: 12
Respuesta: Problema con paginacion

Este es el codigo de reportes.php:
Aquí lo que hago es crear el formulario de busqueda y al precionar el boton buscar cargue el contenido de la segunda seccion.

Código PHP:
Ver original
  1. <?php if(!isset($_GET['search'])): ?>
  2.         <section id="advanceSearch">
  3.             <h1>Búsqueda avanzada</h1><hr />
  4.             <form action="" method="get">
  5.                 <label>Desde: </label><input type="text" name="desde" readonly />
  6.                 <input type="button" onclick="displayCalendar(document.forms[0].desde,'yyyy/mm/dd',this)"/>
  7.                 <label>Hasta: </label> <input type="text" name="hasta" readonly />
  8.                 <input type="button" onclick="displayCalendar(document.forms[0].hasta,'yyyy/mm/dd',this)"/>
  9.                 <br />
  10.                 <label>Cliente: </label> <input type="text" name="cliente" id="cliente" size="60" disabled="disabled" />
  11.                 <br />
  12.                 <label>Asociado: </label><select name="asociados" disabled="disabled" >
  13.                 <option selected="selected">.::Asociados::.</option>
  14.                 <?php
  15.                 if($asociados=$reportes->listarAsociados()):
  16.                     foreach($asociados as $asociado): ?>
  17.                     <option value="<?php echo $asociado->asociadoID; ?>"><?php echo $asociado->nombreAsociado; ?></option>
  18.                 <?php
  19.                     endforeach;
  20.                 endif; ?>
  21.                 </select>
  22.                 <div id="search"><input type="submit" name="search" value="Buscar"></div>
  23.                 <div class="clear" ></div>
  24.             </form>
  25.         </section>
  26.        
  27.         <?php else:?>
  28.        
  29.         <section id="filtrados">
  30.         <h1>Se encontraron <?php echo $reportes->encontrados($_GET['desde'],$_GET['hasta']); ?> coincidencias a tu búsqueda.</h1>
  31.             <?php    
  32.             include 'paginador_resultados.php';
  33.             ?>
  34.         </section>
  35.         <?php endif; ?>

Y este es el archivo paginador_resultados.php

En este se recibe la variable de pag de la function de ajax y recibo tambien los get de las cajas de texto para mandarlas a otras funciones que me devuelven los resultados de las query´s.

Código PHP:
Ver original
  1. <?php
  2. require_once '../clases/connection.class.php';
  3. require_once '../clases/reportes.class.php';
  4.  
  5. $connection=new Connection();
  6. $reportes=new reportes($connection);
  7.  
  8.  $RegistrosAMostrar=10;
  9.  
  10.  //estos valores los recibo por GET
  11.  if(isset($_GET['pag'])){
  12.   $RegistrosAEmpezar=($_GET['pag']-1)*$RegistrosAMostrar;
  13.   $PagAct=$_GET['pag'];
  14.   //caso contrario los iniciamos
  15.  }else{
  16.   $RegistrosAEmpezar=0;
  17.   $PagAct=1;
  18.  }              
  19. ?>
  20. <table width="100%">
  21.       <thead>
  22.         <tr>
  23.             <th>Folio</th>
  24.             <th>Fecha</th>
  25.             <th>Folio fiscal</th>
  26.             <th>Cliente</th>
  27.             <th>Subtotal</th>
  28.             <th>Iva</th>
  29.             <th>Total</th>
  30.             <th>PDF</th>
  31.         </tr>
  32.        </thead>
  33. <?php
  34.  if($filtrado=$reportes->listarResultados($_GET['desde'],$_GET['hasta'],$RegistrosAEmpezar,$RegistrosAMostrar)):
  35.        foreach($filtrado as $filtro): ?>
  36.        <tbody>
  37.             <tr>
  38.                 <td><?php echo $filtro->folio; ?></td>
  39.                 <td><?php echo $filtro->fecha; ?></td>
  40.                 <td><?php echo $filtro->folioFiscal; ?></td>
  41.                 <td><?php echo $filtro->cliente; ?></td>
  42.                 <td><?php echo "$ ".number_format($filtro->subtotaFactura,2,'.',','); ?></td>
  43.                 <td><?php echo "$ ".number_format($filtro->ivaFactura,2,'.',','); ?></td>
  44.                 <td><?php echo "$ ".number_format($filtro->totalFactura,2,'.',','); ?></td>
  45.                 <td><?php echo $filtro->nombrePDF; ?></td>
  46.             </tr>  
  47.        </tbody>
  48.  <?php endforeach;
  49.  endif; ?>
  50.        <tfoot>
  51.             <tr>
  52.                 <td colspan="6">&nbsp;</td>
  53.                 <td><?php echo "$ ".number_format($filtro->totalGeral,2,'.',','); ?></td>
  54.             </tr>
  55.        </tfoot>
  56. </table>
  57.  
  58.  
  59. <?php
  60.  //******--------determinar las p‡ginas---------******//
  61.  $NroRegistros=$reportes->encontrados($_GET['desde'],$_GET['hasta']);
  62.  $PagAnt=$PagAct-1;
  63.  $PagSig=$PagAct+1;
  64.  $PagUlt=$NroRegistros/$RegistrosAMostrar;
  65.  
  66.  //verificamos residuo para ver si llevar‡ decimales
  67.  $Res=$NroRegistros%$RegistrosAMostrar;
  68.  // si hay residuo usamos funcion floor para que me
  69.  // devuelva la parte entera, SIN REDONDEAR, y le sumamos
  70.  // una unidad para obtener la ultima pagina
  71.  if($Res>0) $PagUlt=floor($PagUlt)+1;
  72.  
  73.  //desplazamiento
  74.  ?>
  75.  <a onclick="Pagina('1',<?php echo $_GET['desde'].','.$_GET['hasta'] ?>)" >Primero</a>
  76.  <?php if($PagAct>1) ?><a onclick="Pagina(<?php echo $PagAnt.','.$_GET['desde'].','.$_GET['hasta'] ?>)">Anterior</a>
  77. <strong>Pagina <?php echo $PagAct."/".$PagUlt ?></strong>
  78.  <?php if($PagAct<$PagUlt) ?><a onclick="Pagina(<?php echo $PagSig.','.$_GET['desde'].','.$_GET['hasta'] ?>)" >Siguiente</a>
  79.  <a onclick="Pagina(<?php echo $PagUlt.','.$_GET['desde'].','.$_GET['hasta'] ?>)" >Ultimo</a>
__________________
Lo imposible solo cuesta un poco mas