Foros del Web » Programando para Internet » PHP »

Php Noticia como Anteriores Y Siguientes

Estas en el tema de Php Noticia como Anteriores Y Siguientes en el foro de PHP en Foros del Web. Hola todos Pero el php noticia como Anteriores Y Siguientes ultima 10?? Código PHP: <? $server = "localhost" ; $username = "root" ; $password = ...
  #1 (permalink)  
Antiguo 12/06/2008, 05:27
Avatar de camilo_1987  
Fecha de Ingreso: junio-2008
Ubicación: ALZIRA, Spain, Spain
Mensajes: 77
Antigüedad: 15 años, 10 meses
Puntos: 0
Busqueda Php Noticia como Anteriores Y Siguientes

Hola todos
Pero el php noticia como Anteriores Y Siguientes ultima 10??
Código PHP:
<?
$server
="localhost";
$username="root";
$password="980980";
$database="bonaventura";
$connection=mysql_connect ($server$username$password);
mysql_select_db($database$connection);
$sentencia=mysql_db_query("bonaventura""SELECT * FROM noticia ORDER BY id DESC");
while(
$rs=mysql_fetch_array($sentencia)){
?>
      <table width="95%" border="0" align="center" cellspacing="0">
  <tr>
    <td bgcolor="#90A5CD"><font face="Verdana" size="2">
            <? echo $rs["Titulo"]; ?> - <? echo $rs["Fecha"]; ?></font></td>
  </tr>
  <tr>
    <td align="left"><? echo $rs["Texto"]; ?></td>
  </tr>
</table><? ?>
  #2 (permalink)  
Antiguo 12/06/2008, 06:07
Avatar de Tokkara  
Fecha de Ingreso: junio-2008
Mensajes: 131
Antigüedad: 15 años, 11 meses
Puntos: 5
Respuesta: Php Noticia como Anteriores Y Siguientes

Usa la clausua de MySQL LIMIT para mostrarlas a trozos.

Código PHP:
<?
$server
="localhost";
$username="root";
$password="980980";
$database="bonaventura";
$offset 10//Numero de noticias
$posicion = (int) ($_GET["pos"]*$offset); //Numero de noticia desde la cual va a empezar a mostrarlas
$siguiente $_GET["pos"]+1//variable siguiente
$anterior $_GET["pos"] == $_GET["pos"]-1//variable anterior
$limit " LIMIT ".$posicion.", ".$offset;

$connection=mysql_connect ($server$username$password);
mysql_select_db($database$connection);
$sentencia=mysql_db_query("bonaventura""SELECT * FROM noticia ORDER BY id DESC".$limit);
while(
$rs=mysql_fetch_array($sentencia)){
?>
      <table width="95%" border="0" align="center" cellspacing="0">
  <tr>
    <td bgcolor="#90A5CD"><font face="Verdana" size="2">
            <? echo $rs["Titulo"]; ?> - <? echo $rs["Fecha"]; ?></font></td>
  </tr>
  <tr>
    <td align="left"><? echo $rs["Texto"]; ?></td>
  </tr>
</table><? ?> 

<a href ="<? echo $_SERVER["PHP_SELF"]."?pos=".$anterior?>">Anterior</a>
<a href ="<? echo $_SERVER["PHP_SELF"]."?pos=".$siguiente?>">Siguiente</a>
Algo asi???. A ver q tal te funciona.
Saludos
  #3 (permalink)  
Antiguo 12/06/2008, 06:19
Avatar de camilo_1987  
Fecha de Ingreso: junio-2008
Ubicación: ALZIRA, Spain, Spain
Mensajes: 77
Antigüedad: 15 años, 10 meses
Puntos: 0
Respuesta: Php Noticia como Anteriores Y Siguientes

muy bien gracias!
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 15:58.