Foros del Web » Programando para Internet » PHP »

Paginación

Estas en el tema de Paginación en el foro de PHP en Foros del Web. Hola buenas, mirad, estoy haciendo una seccion de noticias y quiciera ponerle una paginación para que aparezcan unas 10 por página. Como podria hacer esto? ...
  #1 (permalink)  
Antiguo 15/05/2007, 18:38
 
Fecha de Ingreso: mayo-2005
Mensajes: 94
Antigüedad: 18 años, 11 meses
Puntos: 0
Paginación

Hola buenas, mirad, estoy haciendo una seccion de noticias y quiciera ponerle una paginación para que aparezcan unas 10 por página. Como podria hacer esto? La web es la siguiente.

Código PHP:
<?php
error_reporting
(E_ALL); 
require(
"includes/conn.php");
$link Conectarse();
$contar mysql_query("SELECT * FROM noticias") or die(mysql_error());
$sacarnoticias mysql_query("SELECT * FROM noticias order by id DESC") or die(mysql_error());
while (
$contador mysql_fetch_assoc($contar)){
$conta++;
}
?>
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="estilos.css" rel="stylesheet" type="text/css">
</head>
<style>
<!--
body
{
scrollbar-face-color: #FFFFFF;
scrollbar-arrow-color:  #FA0000;
scrollbar-highlight-color: #ffffff;
scrollbar-3dlight-color:  #FFFFFF;
scrollbar-shadow-color: #FFFFFF;
scrollbar-darkshadow-color: #FA0000;
scrollbar-track-color: #FFFFFF;<br>
background-color: #FA0000
}
//-->
</style>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<? if ($conta<1){?>
<br>
<div align="center"><span class="texto">No Hay Productos en esta Sección</span></div><? }?>
<? 
while ($vernoticias mysql_fetch_assoc($sacarnoticias)){
$foto $vernoticias["foto"];
$copete $vernoticias["copete"];
$id $vernoticias["id"];
$title $vernoticias["titulo"];
?><table width="400" height="98" border="0" cellpadding="0" cellspacing="0" class="estilos">
  <tr><? if ($foto!=""){?>
    <td width="95" height="90"> 
      <div align="justify"> <span class="texto"><img src="../fotos/<? echo $foto?>" width="90" height="90" hspace="0" vspace="0" align="left"></span></div></td><? } else { ?>
    <td width="95" height="90"><img src="blank.gif" width="90" height="90" hspace="0" vspace="0" align="left"></td>
    <? ?>
    <td width="284" valign="top"><br>
      <table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">
        <tr><?
        
if(strlen($title)>70) {?>
          <td align="left"><span class="texto"><? print substr($title070); ?>... 
            </span> 
            <? }
        else {
?>
          <td align="left"><span class="texto"><? print substr($title070); ?> </span> <? ?>
        </tr>
        <tr>
          <td align="left"><span class="texto"><? echo eregi_replace(chr(13),"<br>",$copete),"[...]"?> 
            <a href="../noticia.php?id=<? echo $id?>" class="enlaces">leer m&aacute;s 
            &gt;&gt;</a></span> </td>
        </tr>
      </table></td>
  </tr>
</table>
<br>
<table width="400" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td height="6"><img src="imagenes/separa.gif" width="400" height="6"></td>
  </tr>
</table>
<? ?>
</body>
</html>

La seccion que pongo a continuacion es la que necesito paginar, ahora mismo esta sacando todos los resultados

Código PHP:
<? while ($vernoticias mysql_fetch_assoc($sacarnoticias)){
$foto $vernoticias["foto"];
$copete $vernoticias["copete"];
$id $vernoticias["id"];
$title $vernoticias["titulo"];
?><table width="400" height="98" border="0" cellpadding="0" cellspacing="0" class="estilos">
  <tr><? if ($foto!=""){?>
    <td width="95" height="90"> 
      <div align="justify"> <span class="texto"><img src="../fotos/<? echo $foto?>" width="90" height="90" hspace="0" vspace="0" align="left"></span></div></td><? } else { ?>
    <td width="95" height="90"><img src="blank.gif" width="90" height="90" hspace="0" vspace="0" align="left"></td>
    <? ?>
    <td width="284" valign="top"><br>
      <table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">
        <tr><?
        
if(strlen($title)>70) {?>
          <td align="left"><span class="texto"><? print substr($title070); ?>... 
            </span> 
            <? }
        else {
?>
          <td align="left"><span class="texto"><? print substr($title070); ?> </span> <? ?>
        </tr>
        <tr>
          <td align="left"><span class="texto"><? echo eregi_replace(chr(13),"<br>",$copete),"[...]"?> 
            <a href="../noticia.php?id=<? echo $id?>" class="enlaces">leer m&aacute;s 
            &gt;&gt;</a></span> </td>
        </tr>
      </table></td>
  </tr>
</table>
<br>
<table width="400" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td height="6"><img src="imagenes/separa.gif" width="400" height="6"></td>
  </tr>
</table>
<? ?>

Desde ya muchisimas gracias!! Saludos!!
  #2 (permalink)  
Antiguo 16/05/2007, 00:18
Avatar de ZiTAL  
Fecha de Ingreso: marzo-2004
Ubicación: Bermio (Bizkaia)
Mensajes: 1.545
Antigüedad: 20 años, 1 mes
Puntos: 62
Re: Paginación

utiliza limit en los select, ejemplo:

select * from tabla limit 0,10

te pillara los 10 primeros ya que empieza por 0 no por 1.

select * from tabla limit 9,10

te pillara del 10 al 20

select * from tabla 5,2

te pillara 2 a partir del registro 6.

Ahora tienes que programar que numeros deben de ir en los limit ;)
__________________
http://zital.no-ip.org
____________________

Euskerie ahuen eta bijotzan
  #3 (permalink)  
Antiguo 16/05/2007, 06:23
 
Fecha de Ingreso: mayo-2005
Mensajes: 94
Antigüedad: 18 años, 11 meses
Puntos: 0
Re: Paginación

Gracias, ya lo solucione ;)

Saludosss
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 00:02.