·
miarroba.com

Paginacion (creo q es asi)
  · Índice de subforos · PHP

Buscar · Tags · Tagboard · Usuarios · Fisgona · F.A.Q.

Autor Mensaje 
bellacordbellacord
Come y duerme en el foro
Come y duerme en el foro

Haz clic para ver el perfil del usuario
Mensajes: 490
Desde: 31/May/2003
Paginacion (creo q es asi)

Como puedo hacer para poner los link automaticamente en una pagina web, asi por secciones como lo muestran los foros, es decir Index - Seccion 2- Seccion 3, casa uno con sus link, lo quisiera poner mediante codigos o base de datos, no insercion mediante html, o sea, manualmente, no uno por cada pagina...a ver si me entineden...
18/May/2006 22:42 GMT+1 Perfil ·  Privado · Desconectado ·  Web
Satan_huseinSatan_husein
@man / @woman
@man / @woman

Haz clic para ver el perfil del usuario
Mensajes: 1.875
Desde: 14/Abr/2003
RE: Paginacion (creo q es asi)

paginador.php
<?php
// Clase de paginacion
class Paging
{
// Varibles to be uses as Menu Config
// If not set with the proper Function
// they get a default Value

/* How Many result Per Page
@INT
*/
var $perPage;
/* String with the next Link-Text
@STR : Can be html to use images <img src="img/next.gif" alt="next">
*/
var $strNext;
/* String with the next Link-Text
@STR : Can be html to use images <img src="img/next.gif" alt="next">
*/
var $strPrev;
/* String with the Var name that will be used for Paging
@STR : Use Only [a-z][A-Z] Chars Please (DO NOT INCLUDE [0-9])
*/
var $varName;

// Variables For Calculation Of Result

/* Variable that Holds The Number Of Results In the Query
@INT
*/
var $total;
/* Total Number Of Pages
$INT
*/
var $totalPages;
/* Variable that Holds the number of the begibib in the query
@INT
*/
var $start;
/* THe current Value of $_GET[ $varName ]
@INT
*/
var $page;


// Variables for Storing Mysql Querys And Results

/* This Variable Holds the Original Query Of the User
@STR
*/
var $sql;


// Class Constructor PASS the query
// Only Selects
function Paging($sql)
{
// Store the Original SQL
$this->sql = $sql;
// Get The SQL Count Query String
$sqlCount = eregi_replace("select (.*) from", "SELECT COUNT(*) FROM", $this->sql);
// Fetch the Result
$sqlCount = mysql_query($sqlCount);
// Set the Total
$this->total = mysql_result($sqlCount,0,0);
}

// Method Used Internaly to Propage the URL GET Variables
function propagate(&$a,$pref='',$f='',$idx='')
{
$ret = '';
foreach ($a as $i => $j)
{
if ($i != $this->varName)
{
if ($idx != '')
{
$i = $idx."[$i]";
}
if (is_array($j))
{
$ret .= $this->propagate($j,'',$f,$i);
}
else
{
$j=urlencode($j);
if (is_int($i))
{
$ret .= "$f$pref$i=$j";
}
else
{
$ret .= "$f$i=$j";
}
}
}
$f='&';
}
return $ret;
}


// Methods For Configuration
function set_perPage($value)
{
$this->perPage = $value;
}

function set_strNext($value)
{
$this->strNext = $value;
}

function set_strPrev($value)
{
$this->strPrev = $value;
}

function set_varName($value)
{
$this->varName = $value;
}

function sysConfig()
{
// This Method Calls All all the Config Methods
// To configure the Class
if (empty($this->varName))
{
$this->set_varName('page');
}
if (empty($this->strPrev))
{
$this->set_strPrev('<< ');
}
if (empty($this->strNext))
{
$this->set_strNext(' >>');
}
if (empty($this->perPage))
{
$this->set_perPage(10);
}
$this->page = isset($_GET[$this->varName]) ? $_GET[$this->varName] : 1;
$this->totalPages = ceil($this->total / $this->perPage);
$this->start = ($this->page - 1) * $this->perPage;
}

function getMenu()
{
// Config CALL
$this->sysConfig();
$string = $this->propagate($_GET);
$more = $this->page + 1;
$less = $this->page - 1;
if ($this->page != 1)
{
$navResult[] = "<a href=\"$_SERVER[PHP_SELF]?$string&$this->varName=$less\">$this->strPrev</a>";
}
for ($i=1;$i<=$this->totalPages;$i++)
{
$navResult[] = ($this->page == $i) ? " <strong>$i</strong> " : "<a href=\"$_SERVER[PHP_SELF]?$string&$this->varName=$i\">$i</a>";
}
if ($this->page != $this->totalPages)
{
$navResult[] = "<a href=\"$_SERVER[PHP_SELF]?$string&$this->varName=$more\">$this->strNext</a>";
}
$navResult = implode($navResult,' | ');
$navResult = "Mostrando Pagina $this->page de $this->totalPages - $this->total Registros<br/>" .$navResult;
return $navResult;
}

function getResult()
{
$this->sysConfig();
$this->sql .= " LIMIT $this->start, $this->perPage";
$result = mysql_query($this->sql);
return $result;
}

function debug()
{
echo '<textarea cols="60" rows="10">';
print_r($this);
echo '</textarea>';
}

}

?>ç


***************************
Ejemplo de como usarlo
<?
include('paginador.php');

$paging =& new Paging('SELECT * FROM usuarios');

$paging->set_perPage(10);
// te muestra X registros por pagina
// si no lo llamas el default es 10
$paging->set_strNext('>>');
$paging->set_strPrev('<<');
// Cual sera el str del boton siguiente y anterior?
// los defaults son >> <<
// puede ser incluso una imagen (html : <img src="...">) ;)
$paging->set_varName('page');
// pudes cambiarle el nombre a la variable GET
// sease http://web.com/usuarios.php?page=1
// sease http://web.com/usuarios.php?pagina=1
// sease http://web.com/usuarios.phpfuck=1
// sease http://web.com/usuarios.php?loquesea=1
// el default es page

$res = $paging->getResult();
$nav = $paging->getMenu();

while($row = mysql_fetch_array($res))
{
echo "<b>$row[id_user]</b>:$row[userName] <br/>\n";
}
echo $nav;
?>
19/May/2006 04:18 GMT+1 Perfil ·  Privado · Desconectado ·  Web
inigoruizinigoruiz
Machacateclados
Machacateclados

Haz clic para ver el perfil del usuario
Mensajes: 199
Desde: 18/Ene/2006
RE: Paginacion (creo q es asi)

exacto
21/May/2006 01:19 GMT+1 Perfil ·  Privado · Desconectado ·  Web
marianobrusmarianobrus
Usuario Novato
Usuario Novato


Mensajes: 2
Desde: 24/Nov/2007
RE: Paginacion (creo q es asi)

yo lo inserto y me aparece la barra de navegacion, pero el problema que tengo es que no puedo mostrar la cantidad de datos que quiero, me muestra todo, este es el codigo que me levanta los datos, creo que ahi debe haber un error:

 <?
     //if($seccion == 0)
      $query = "SELECT * FROM catalogo WHERE seccion_ita = 'Documentari' AND estado = 1 ORDER BY 1";
     //else
      //$query = "SELECT * FROM noticias WHERE IDSeccion = '".$seccion."' AND Habilitado = 1 ORDER BY OrdenHome ";

    $res = mysql_query($query);
    $total_registros = mysql_num_rows($res);

    if($total_registros > 0)
    {

     for($i=0;$i<@mysql_num_rows($res);$i++)
     {
      $cuando = "hoy por la ma&ntilde;ana";
      $IDCatalogo = mysql_result($res,$i,"IDCatalogo" ;
      $titolo_ita = mysql_result($res,$i,"titolo_ita" ;
      $titolo_ing = mysql_result($res,$i,"titolo_ing" ;
      $attore_ita  = mysql_result($res,$i,"attore_ita" ;
      $attore_ing  = mysql_result($res,$i,"attore_ing" ;
      $regia_ita = mysql_result($res,$i,"regia_ita" ;
      $regia_ing = mysql_result($res,$i,"regia_ing" ;
      $produzione_ita = mysql_result($res,$i,"produzione_ita" ;
      $produzione_ing = mysql_result($res,$i,"produzione_ing" ;
      $durata_ita = mysql_result($res,$i,"durata_ita" ;
      $durata_ing = mysql_result($res,$i,"durata_ing" ;
      $genere_ita = mysql_result($res,$i,"genere_ita" ;
      $genere_ing = mysql_result($res,$i,"genere_ing" ;

      $imagen = mysql_result($res,$i,"imagen" ;

      
?>



Editado por marianobrusmarianobrus, Sábado, 24 de Noviembre de 2007, 17:30
24/Nov/2007 17:29 GMT+1 Perfil ·  Privado · Desconectado
Publicidad
· Índice de subforos · PHP

Temas similares Autor#VisitasÚltimo post
Paginacion PHP24/Nov/2007, 16:07
marianobrusmarianobrus
 0 831No hay respuestas
Creo que esta es facil02/Oct/2004, 02:05
alekulaalekula
 5 36107/Oct/2004, 02:09
Atomo64Atomo64 Ir al último mensaje del tema
COmo creo un Foro ??11/Sep/2002, 23:58
eLGiOvAeLGiOvA
 1 91019/Nov/2002, 20:27
xlonyxlony Ir al último mensaje del tema
COMO CREO LAS TABLAS ??????????????????22/Ago/2003, 16:57
hks-3207hks-3207
 8 85112/Sep/2003, 06:51
MaIcOlMaIcOl Ir al último mensaje del tema
Como me creo un registro de usuarios por php?21/Sep/2004, 04:03
NimajnebNimajneb
 2 53422/Sep/2004, 20:52
ivanitowebivanitoweb Ir al último mensaje del tema

Opciones:

Versión imprimible del tema
Subscríbete a este tema
Date de baja de este tema
Menear este tema en meneame.net
Ir al subforo:  

TU NO PUEDES Escribir nuevos temas en este foro
TU NO PUEDES Responder a los temas en este foro
TU NO PUEDES Editar tus propios mensajes en este foro
TU NO PUEDES Borrar tus propios mensajes en este foro

Todas las fechas y horas son GMT+1. Ahora son las 13:39
Miarroba Networks, S.L. Apartado de correos, 50, 39610 Astillero (CANTABRIA) - CIF B-39512736
Inscrita en el Registro Mercantil de Cantabria, tomo 743, folio 161, libro 0, hoja S-12428, Instripción 1ª