Ver Mensaje Individual
  #6 (permalink)  
Antiguo 06/05/2012, 15:31
Avatar de Ex_shadow
Ex_shadow
 
Fecha de Ingreso: febrero-2012
Ubicación: Calera Avellaneda, Buenos Aires, Argentina, Argentina
Mensajes: 95
Antigüedad: 12 años, 2 meses
Puntos: 4
Respuesta: Paginacion en php While dentro de funcion?

jajajaja xD perdon aveces soy medio navo xD

acá esta:

Código PHP:
Ver original
  1. /* --- *** --- Mysql --- *** --- */
  2. # --- Conexion mysql
  3. function Conectar ($Host,$Usuario,$Contrasena,$Base){
  4.    
  5.     $Conexion = mysql_connect($Host,$Usuario,$Contrasena);
  6.     return mysql_select_db($Base,$Conexion);
  7.    
  8. }
  9.  
  10. # --- Consulta
  11. function Consulta($Consult){
  12.    
  13.     return mysql_query($Consult);
  14.    
  15. }
  16.  
  17. # --- Reg_Num
  18. function Reg_Num($Consult){
  19.    
  20.     return mysql_num_rows($Consult);
  21.    
  22. }
  23.  
  24. # --- Asooc
  25. function Assoc($Consult){
  26.     return mysql_fetch_assoc($Consult);
  27. }
  28.  
  29.  
  30. /* --- *** --- Scripts --- *** --- */
  31. # --- Paginador
  32. function Paginador($Consult,$Reg,$Botones,$Class,$Funcion){
  33.     # - Posicion
  34.     if(!isset($_GET['Pag']) || $_GET['Pag']<0){ // Si no Existe Pag o Es menor a 0
  35.         $Pagina = 1;
  36.     }else{
  37.         $Pagina = $_GET['Pag'];
  38.     }
  39.    
  40.     # - Opciones
  41.     $Consulta = Consulta($Consult);
  42.     $Registros = $Reg;
  43.     $Intervalo = $Botones;
  44.    
  45.     # - Configuracion
  46.     $Cantidad = Reg_Num($Consulta);
  47.     $Desde = ($Pagina-1)*$Registros;
  48.     $Total = ceil($Cantidad/$Registros);
  49.     $Botones = ($Intervalo*2)+1;
  50.     $i = 0;
  51.     $Func = $Pagina-$Intervalo;
  52.    
  53.     $Consult .=' LIMIT '.$Desde.' , '.$Registros; // *** Ok
  54.    
  55.     # - Navegacion
  56.     $Anterior = $Pagina-1;
  57.     $Siguiente = $Pagina+1;
  58.        
  59.     # - Bucle
  60.     while($Campo = Assoc($Consult)){
  61.        
  62.              $Funcion();
  63.  
  64.     }
  65.    
  66.     # -- Empieza la Navegacion
  67.     # - Boton Anterior
  68.     if($Pagina>1){
  69.         echo '<a href="?Pag='.$Anterior.'"> <input type="button" class="Navegacion" value="Anterior"> </a>';
  70.     }
  71.    
  72.     # - Paginas
  73.     while ($i<$Botones) {
  74.      
  75.         if ($Func>0 and $Func<=$Total) {
  76.    
  77.             if($Func == $Pagina){
  78.                 echo '<input type="button" class="'.$Class.' Disabled" value="'.$Func.'" disabled="disabled"/>';
  79.             }else{
  80.               echo '<a href="?Pag='.$Func.'"> <input type="button" class="'.$Class.'" value="'.$Func.'" />  </a>';
  81.             }
  82.          $i++;
  83.         }
  84.    
  85.             if($Func>$Total){
  86.                 $i=$Botones;
  87.             }
  88.          $Func++;
  89.         }
  90.    
  91.     /* Simple
  92.     echo $Pagina.' / '.$Total;*/
  93.  
  94.     # - Boton Siguiente
  95.     if($Pagina>=1 and $Pagina<$Total || !isset($_GET['Pag'])){
  96.         echo '<a href="?Pag='.$Siguiente.'"> <input type="button" class="Navegacion" value="Siguiente"> </a>';
  97.     }  
  98. }


Código PHP:
Ver original
  1. <?
  2.             include("Includes/Paginador.php");
  3.            
  4.             function Mostrador(){
  5.                 echo $Campo['Nombre'];
  6.             }
  7.            
  8.             Conectar('localhost','root','','mysql');
  9.            
  10.             Paginador("SELECT * FROM help_relation",20,2,'Paginas',Mostrador);
  11.         ?>


El error {

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\UndeRock\Includes\Paginador.php on line 27

}

En cuanto le puse el "LIMIT" me devolvia un error, pero si le hago un echo a esa consulta con el limit y la pongo en el phpmyadmin me funciona bien ahi la consulta, en el php no.

Última edición por Ex_shadow; 06/05/2012 a las 15:37