Foros del Web » Programando para Internet » PHP »

fgets??

Estas en el tema de fgets?? en el foro de PHP en Foros del Web. Hola antes que nada y espero que puedan ayudarme, ya que de PHP ando más bien tieso. Tengo el siguiente código que me permite llamar ...
  #1 (permalink)  
Antiguo 01/10/2003, 16:19
 
Fecha de Ingreso: noviembre-2002
Mensajes: 59
Antigüedad: 21 años, 5 meses
Puntos: 0
fgets??

Hola antes que nada y espero que puedan ayudarme, ya que de PHP ando más bien tieso.
Tengo el siguiente código que me permite llamar línea a linea o bien a toda la base de datos que tengo almacenada en un txt, y lo que me guustaría saber es si hay alguna forma de llamarla de cinco en cinco registros y que se generen los enlaces automáticamente dependiendo del número de entradas.

Gracias por adelantado.

Código PHP:
<?php





$size
=filesize("compra.txt");

if (!
$size =="0") {




$fp fopen("compra.txt","r");
$line 0;
while (!
feof ($fp) )
{       
$uname fgets($fp,filesize("compra.txt"));
        
$line $line 1;

$uname2=chop($uname);
$res preg_split("/####/",$uname2);



if (
$res[0] || $res[1] || $res[2] || $res[3] || $res[4]  || $res[5]  || $res[6]  || $res[7]  || $res[8]  || $res[9]  || $res[10] ) {

if (
$line == "$entry") {



          

echo 
"<table $tablestuff>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>id<td $tdstuff><font face =$font size=$fsize color=$fcolor>$line<TR>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field1name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[0]<TR>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field2name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[1]<TR>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field3name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[2]<tr>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field4name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[3]<tr>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field5name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[4]<tr>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field6name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[5]<tr>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field7name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[6]<tr>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field8name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[7]<tr>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field9name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[8]<tr>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field10name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[9]<tr>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>Date<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[10]";
echo 
"</table><BR><br>";


}
}

if (
$res[0] || $res[1] || $res[2] || $res[3] || $res[4]  || $res[5]  || $res[6]  || $res[7]  || $res[8]  || $res[9]  || $res[10] ) {

if (
$entry == "all") {


          

echo 
"<table $tablestuff>";
//echo "<td $tdstuff><font face =$font size=$fsize color=$fcolor>id<td $tdstuff><font face =$font size=$fsize color=$fcolor>$line<TR>";
echo "<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field1name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[0]<TR>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field2name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[1]<TR>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field3name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[2]<tr>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field4name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[3]<tr>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field5name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[4]<tr>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field6name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[5]<tr>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field7name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[6]<tr>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field8name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[7]<tr>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field9name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[8]<tr>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field10name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[9]<tr>";
echo 
"<td $tdstuff><font face =$font size=$fsize color=$fcolor>Date<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[10]";
echo 
"</table><BR><br>";


}
}





}
fclose($fp);

}




?>
  #2 (permalink)  
Antiguo 03/10/2003, 23:57
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Pues .. si, forma hay ..

Busca en el foro por "paginar" o "paginacion" .. la técnica es igual a la que se usa con Base de datos (Mysql etc ..) sólo que tus "consultas" no son tales sino que es coger rangos de tu array que obtienes en $uname o $uname2 ...

Si mal no recuerdo Josemi (moderador del foro PHP ;) ) hizo un ejemplo de paginación de arrays .. como para que lo adaptes ..

Un saludo,
__________________
Por motivos personales ya no puedo estar con Uds. Fue grato haber compartido todos estos años. Igualmente los seguiré leyendo.
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 14:37.