• Publicidad

Mostrar 25 registros por página

¿Apenas comienzas con Perl? En este foro podrás encontrar y hacer preguntas básicas de Perl con respuestas aptas a tu nivel.

Mostrar 25 registros por página

Notapor globalworkteam » 2012-09-30 19:40 @861

Hola.

Quisiera que en el siguiente script sólo me aparecieran 25 registros por página, es decir, 25 registros en la primera página, y si hay más registros en sucesivas páginas.

Muchas gracias.

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!/usr/bin/perl
  2.  
  3. use CGI::Carp qw( fatalsToBrowser );
  4.  
  5. do 'sessions.cgi';
  6. do 'paidmembers.cgi';
  7.  
  8. if ( $ENV{REQUEST_METHOD} eq 'POST' ) {
  9.     read( STDIN, $buffer, $ENV{'CONTENT_LENGTH'} );
  10. }
  11. else { $buffer = $ENV{QUERY_STRING} }
  12. @pairs = split( /&/, $buffer );
  13. foreach $pair (@pairs) {
  14.     ( $name, $value ) = split( /=/, $pair, 2 );
  15.     $value =~ tr/+/ /;
  16.     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  17.     $in{$name} = $value;
  18. }
  19.  
  20. print "Content-type:text/html\n\n";
  21. $session = $in{'session'};
  22. $session =~ /:(\d+)/;
  23.  
  24. unless ( $in{'submit'} ) {             #'submit' not clicked, show form
  25.     $filesize = ( stat("$Database") )[7];
  26.     if ( $filesize % $DBRecSize != 0 ) { die "Database processing error!" }
  27.     $users = $filesize / $DBRecSize;
  28.  
  29.     print qq~
  30. <html>
  31.   <head>
  32.     <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  33.     <title>Search account information</title>
  34.   </head>
  35.   <body background="$SiteURL/bg.jpg">
  36.     <h2 align="center">Search/Browse account information<br></h2>
  37.     <form action="searchb.cgi" method="POST">
  38.       <center>
  39.         <table border="1" cellpadding="1" cellspacing="0" bgcolor="#FFFFCC">
  40.           <tr><td>User ID#: </td><td><input type="text" size="6" name="userid"></td></tr>
  41.           <tr><td>Name: </td><td><input type="text" size="40" name="name"></td></tr>
  42.           <tr><td>Socio: </td><td><input type="text" size="40" name="socio"></td></tr>
  43.           <tr><td>Email: </td><td><input type="text" size="40" name="email"></td>
  44.           <tr><td>Search from#: </td><td><input type="text" size="6" name="startid" value="2"></td></tr>
  45.           <tr><td>Search to#: </td><td><input type="text" size="6" name="endid" value="$users"></td></tr>
  46.           <INPUT type="hidden" name="session" value="$session"></tr>
  47.           <tr><td colspan="2"><BR />
  48.             <CENTER>
  49.               <input type="submit" value="Search" name="submit" style="font-size: 17px">
  50.             </CENTER><BR />
  51.             <INPUT type="hidden"></td></tr>
  52.         </table>
  53.       </center>
  54.     </form>
  55.     <center>Note: Search results for User ID# are instant, but for name and email can take some time.<center>
  56. ~;
  57.     exit;
  58. }
  59.  
  60. #if clicked 'submit'
  61.  
  62. $userid = $in{'userid'};
  63. if ( $userid != undef ) { $userid = int($userid) }
  64. $name    = uc( $in{'name'} );
  65. $email   = uc( $in{'email'} );
  66. $socio   = uc( $in{'socio'} );
  67. $startid = int( $in{'startid'} );
  68. $endid   = int( $in{'endid'} );
  69.  
  70. print qq~
  71. <html>
  72.   <head>
  73.     <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  74.   </head>
  75.   <body background="$SiteURL/bg.jpg">
  76. ~;
  77.  
  78. $filesize = ( stat("$Database") )[7];
  79. if ( $filesize % $DBRecSize != 0 ) { die "Database processing error!" }
  80. $users = $filesize / $DBRecSize;
  81. if    ( $startid == undef ) { $startid = 2 }
  82. if    ( $endid == undef )   { $endid   = $users }
  83. if    ( $startid < 2 )      { $startid = 2 }
  84. elsif ( $startid > $users ) { $startid = $users }
  85. if    ( $endid < 2 )        { $endid   = 2 }
  86. elsif ( $endid > $users )   { $endid   = $users }
  87. if    ( $users == 1 )       { $startid = 3 }
  88. if ( ( $userid != undef ) && ( ( $userid < 1 ) || ( $userid > $users ) ) ) {
  89.     print "Such user doesn't exists!";
  90.     exit;
  91. }
  92. if ( $startid == 1 ) { $startid = 2 }
  93.  
  94. open( USERS, "<$Database" ) or die "Error opening database!  $!\n";
  95. if ( $userid != undef ) {
  96.     ReadLock( *USERS, ( $userid - 1 ) * $DBRecSize, $DBRecSize );
  97.     sysseek( USERS, ( $userid - 1 ) * $DBRecSize, 0 ) or die "Error seeking database!  $!\n";
  98. }
  99. else {
  100.     ReadLock( *USERS, ( $startid - 1 ) * $DBRecSize, ( $endid - $startid + 1 ) * $DBRecSize );
  101.     sysseek( USERS, ( $startid - 1 ) * $DBRecSize, 0 ) or die "Error seeking database!  $!\n";
  102. }
  103.  
  104. print
  105.     "<CENTER><table border=1 cellspacing=0><tr><td><B>Foto</B></td><td><B>ID#</B></td><td><B>Name</B></td><td><B>Socio</B></td><td><B>D</B></td><td><B>I</B></td><td><B>R#</B></td><td><B>$PaidName?</B></td><td><B>Balance</B></td></tr>";
  106.  
  107. if ( $userid != 1 ) {
  108.     for ( $n = $startid; $n <= $endid; $n++ ) {
  109.         sysread( USERS, $buffer, $DBRecSize ) or die "Error reading database!  $!\n";
  110.         @user        = split( /$DBFieldSepChar/, $buffer );
  111.         $db_name     = uc( $user[$DBName] );
  112.         $db_socio    = uc( $user[$DBSocio] );
  113.         $db_password = $user[$DBPassword];
  114.         $db_email    = uc( $user[$DBEmail] );
  115.         $dr          = $user[$DBDirectReferrals];
  116.         $ir          = $user[$DBIndirectReferrals];
  117.         $referrer    = $user[$DBReferrer];
  118.         $paid        = "-";
  119.         if ( $user[$DBStatus] == 1 ) { $paid = "<FONT color=green><B>$PaidName</B><FONT>" }
  120.  
  121.         if (    ( $db_password ne "" )
  122.             and ( $user[$DBStatus] == 1 )
  123.             and (
  124.                 ( $userid != undef )
  125.                 or (( ( $name eq undef ) or ( $db_name =~ /$name/ ) )
  126.                     and (   ( ( $socio eq undef ) or ( $db_socio =~ /$socio/ ) )
  127.                         and ( ( $email eq undef ) or ( $db_email =~ /$email/ ) ) )
  128.                 )
  129.             )
  130.             ) {
  131.             if ( $userid != undef ) { $n = $userid }
  132.             $f = $startid++;
  133.             if   ( $f / 2 == int( $f / 2 ) ) { $color = "#DFDFDF" }
  134.             else                             { $color = "#EFEFEF" }
  135.             print "<tr bgcolor=\"$color\">
  136.     <td><img src=\"http:\/\/clubbeeteam.com\/fotos\/$n.jpg\" width=\"122\" height=\"162\"></td><td>$n</td><td>$user[$DBName]</td><td>$user[$DBSocio]</td><td>$dr</td><td>$ir</td><td>$referrer</td><td>$paid</td><td>$user[$DBBalance]</td>
  137.     </tr>";
  138.         }
  139.  
  140.         if ( $userid != undef ) {last}
  141.     }
  142. }
  143.  
  144. print "</table>";
  145. close(USERS);
  146.  
  147. print "<H2>Search completed</H2></CENTER>";
Coloreado en 0.006 segundos, usando GeSHi 1.0.8.4
Última edición por explorer el 2012-09-30 22:31 @980, editado 1 vez en total
Razón: Formateado de código con Perltidy
globalworkteam
Perlero nuevo
Perlero nuevo
 
Mensajes: 14
Registrado: 2012-04-17 20:26 @893

Publicidad

Re: Mostrar 25 registros por página

Notapor explorer » 2012-09-30 22:34 @982

¿Este código es tuyo?

Parece que tiene unos 15 años...
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Mostrar 25 registros por página

Notapor globalworkteam » 2012-10-01 01:43 @113

Lo he modificado de un script.
globalworkteam
Perlero nuevo
Perlero nuevo
 
Mensajes: 14
Registrado: 2012-04-17 20:26 @893

Re: Mostrar 25 registros por página

Notapor danimera » 2012-10-01 11:42 @529

Dios mio. ¿De dónde sacaría ese código...? Es muy pero muy... jaaa... :lol:

Más bien explica qué hace el sistema y se le busca una alternativa mejor ¡ja,ja,ja!
100% Telch - Perl Web Programming
Cali PerlMongers: http://cali.pm.org
Avatar de Usuario
danimera
Perlero frecuente
Perlero frecuente
 
Mensajes: 871
Registrado: 2005-06-23 19:02 @834
Ubicación: Colombia

Re: Mostrar 25 registros por página

Notapor explorer » 2012-10-01 12:21 @556

Por aquí hemos hablado de ese tema: Módulo Data::Page.

Échale un vistazo a ver si te sirve. Si no, vuelve por aquí y lo miraremos con más calma.
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Mostrar 25 registros por página

Notapor globalworkteam » 2012-10-03 04:09 @215

He probado y no funciona.

La página que muestra los registros es esta:

http://clubbeeteam.com/cgi-bin/searchb.cgi

y lo que quiero es que muestre 25 resultados por página, no todos a la vez.

Muchas gracias.
globalworkteam
Perlero nuevo
Perlero nuevo
 
Mensajes: 14
Registrado: 2012-04-17 20:26 @893

Re: Mostrar 25 registros por página

Notapor explorer » 2012-10-03 07:09 @339

¿Qué versión de Perl tienes instalada?

Ejecuta

perl -v
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Mostrar 25 registros por página

Notapor globalworkteam » 2013-01-08 19:17 @845

¿A qué te refieres a que ejecute perl -v??

Un saludo
globalworkteam
Perlero nuevo
Perlero nuevo
 
Mensajes: 14
Registrado: 2012-04-17 20:26 @893

Re: Mostrar 25 registros por página

Notapor explorer » 2013-01-08 19:21 @848

Pues que ejecutando ese comando en la línea de comandos, perl dice qué versión es.

Según sea una versión u otra, se puede encontrar la causa del error. O buscar soluciones más o menos sencillas.
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Mostrar 25 registros por página

Notapor globalworkteam » 2013-01-12 14:59 @666

Hola de nuevo.

Lo que me gustaría hacer es lo siguiente:

Tengo la siguiente página: http://bonusqr.com/ofertas y en esta página en cuanto elijo la ciudad y la categoría me abre una tabla con todos los registros que hay.

De momento hay muy pocos registros pero en el momento que haya muchos me gustaría poner una opción para que solo haya 25 registros por página y en caso de que haya más poner debajo de la tabla la opción de página siguiente.

El script es el siguiente:

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!/usr/bin/perl
  2.  
  3. use CGI::Carp qw( fatalsToBrowser );
  4.  
  5. do 'sessions.cgi';
  6. do 'paidmembers.cgi';
  7.  
  8. if ($ENV{REQUEST_METHOD} eq 'POST') {
  9. read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  10. } else {$buffer = $ENV{QUERY_STRING}}
  11. @pairs = split(/&/, $buffer);
  12. foreach $pair (@pairs)
  13. {($name, $value) = split(/=/, $pair, 2);
  14.  $value =~ tr/+/ /;
  15.  $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  16.  $in{$name} = $value;
  17. }
  18.  
  19. print "Content-type:text/html\n\n";
  20. $session=$in{'session'};
  21. $session=~/:(\d+)/;
  22.  
  23.  
  24. unless($in{'submit'}) { #'submit' not clicked, show form
  25. $filesize = (stat("$Database"))[7];
  26. if ($filesize % $DBRecSize != 0) {die "Database processing error!"}
  27. $users=$filesize / $DBRecSize;
  28.  
  29. print qq~<title>Ofertas Bonus QR - Sorprendete con DESCUENTOS y PROMOCIONES de tu Ciudad</title>~;
  30. do 'header.cgi';
  31. do 'menu.cgi';
  32. print qq~
  33. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  34. <tr>
  35.     <td align="center"><table width="92%" border="0" align="center" cellpadding="0" cellspacing="0">
  36.         <tr>
  37.           <td>&nbsp;</td>
  38.         </tr>
  39.         <tr>
  40.           <td align="center" class="sorprendete">Sorprendete con <strong class="rojo">DESCUENTOS</strong> y <strong class="rojo">PROMOCIONES</strong> de <span class="sorprendetegrande">tu Ciudad</span></td>
  41.         </tr>
  42.         <tr>
  43.           <td align="center">&nbsp;</td>
  44.         </tr>
  45.         <tr>
  46.           <td colspan="2"><div align="center" id="caja">
  47.               <form action="../cgi-bin/ofertas.cgi" method="get" name="" >
  48.                   <table width="100%" border="0" cellspacing="0" cellpadding="0">
  49.                     <tr>
  50.                       <td align="center"><select name="ciudad" id="ciudad" >
  51.                         <option value="" selected>Elige tu Ciudad</option>
  52.                         <option value="Valladolid">Valladolid</option>
  53.                       </select></td>
  54.                     </tr>
  55.                     <tr>
  56.                       <td height="60" align="center" valign="bottom"><select name="categoria" id="categoria">
  57.                         <option value="" selected>Elige Categoria</option>
  58.                         <option value="">Cualquiera</option>
  59.                         <option value="Salud">Salud</option>
  60.                       </select></td>
  61.                     </tr>
  62.                     <tr>
  63.                       <td align="center"><INPUT type="hidden">
  64.                       <input name="starid" type="hidden" id="starid" value="2" />
  65.                       <input name="endid" type="hidden" id="endid" value="$users" />
  66.                       <input name="submit" type="submit" class="submit" id="submit" value="Descubrelo Ahora" /></td>
  67.                     </tr>
  68.                   </table>
  69.               </form>
  70.             </div>
  71.         </tr>
  72.     </table></td>
  73.   </tr>
  74. </table>
  75. </br></br>
  76. ~;
  77. do 'footer.cgi';
  78. exit;
  79. }
  80.  
  81. #if clicked 'submit'
  82.  
  83. $userid=$in{'userid'}; if ($userid!=undef) {$userid=int($userid)};
  84. $ciudad=uc($in{'ciudad'});
  85. $categoria=uc($in{'categoria'});
  86. $startid=int($in{'startid'});
  87. $endid=int($in{'endid'});
  88.  
  89. print qq~<title>Ofertas Bonus QR - Sorprendete con DESCUENTOS y PROMOCIONES de tu Ciudad</title>~;
  90. do 'header.cgi';
  91. do 'menu.cgi';
  92.  
  93. $filesize = (stat("$Database"))[7];
  94. if ($filesize % $DBRecSize != 0) {die "Database processing error!"}
  95. $users=$filesize / $DBRecSize;
  96. if ($startid == undef) {$startid=2};
  97. if ($endid == undef) {$endid=$users};
  98. if ($startid<2) {$startid=2} elsif ($startid>$users) {$startid=$users};
  99. if ($endid<2) {$endid=2} elsif ($endid>$users) {$endid=$users};
  100. if ($users==1) {$startid=3};
  101. if (($userid!=undef) && (($userid<1) || ($userid>$users))) {
  102. print "Such user doesn't exists!";exit};
  103. if ($startid==1) {$startid=2};
  104.  
  105. open(USERS, "<$Database") or die "Error opening database!  $!\n";
  106. if ($userid!=undef) {
  107. ReadLock(*USERS,($userid-1)*$DBRecSize,$DBRecSize);
  108. sysseek(USERS,($userid-1)*$DBRecSize,0) or die "Error seeking database!  $!\n";
  109. } else {
  110. ReadLock(*USERS,($startid-1)*$DBRecSize,($endid-$startid+1)*$DBRecSize);
  111. sysseek(USERS,($startid-1)*$DBRecSize,0) or die "Error seeking database!  $!\n";
  112. };
  113.  
  114. print "<table width=\"92%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
  115.  <tr>
  116.    <td>&nbsp;</td>
  117.  </tr>
  118.  <tr>
  119.    <td align=\"center\" class=\"sorprendete\">Sorprendete con <strong class=\"rojo\">DESCUENTOS</strong> y <strong class=\"rojo\">PROMOCIONES</strong> de <span class=\"sorprendetegrande\">tu Ciudad</span></td>
  120.  </tr>
  121.  <tr>
  122.    <td align=\"center\">&nbsp;</td>
  123.  </tr>
  124.  <tr>
  125.    <td colspan=\"2\"><div align=\"center\" id=\"green\">
  126.        <table width=\"100%\" border=0 cellpadding=\"10\" cellspacing=0\">";
  127.  
  128. if ($userid!=1) {
  129.   for ($n=$startid;$n<=$endid;$n++) {
  130.    sysread(USERS, $buffer, $DBRecSize) or die "Error reading database!  $!\n";
  131.    @user=split(/$DBFieldSepChar/, $buffer);
  132.    $db_ciudad=uc($user[$DBCiudad]);
  133.    $db_categoria=uc($user[$DBCategoria]);
  134.    $db_password=$user[$DBPassword];
  135.    $dr=$user[$DBDirectReferrals];
  136.    $ir=$user[$DBIndirectReferrals];
  137.    $referrer=$user[$DBReferrer];
  138.    $paid="-";
  139.    if ($user[$DBStatus]==1) {$paid="<FONT color=green><B>$PaidName</B><FONT>"};
  140.  
  141.    if (($db_password ne "") and ($user[$DBStatus] eq "1")
  142.       and
  143.       (($userid!=undef) or ((($ciudad eq undef) or ($db_ciudad=~/$ciudad/))
  144.       and
  145.       (($categoria eq undef) or ($db_categoria=~/$categoria/)))))
  146.  
  147.     {
  148.      if ($userid!=undef) {$n=$userid};
  149.      $f=$startid++;
  150.      if ($f/2==int($f/2)) {$color="#E3F0D6"} else {$color="#EFEFEF"};
  151.      print
  152.      "<tr>
  153.          <td id=\"tablalink\" onclick=\"document.location.href='http://bonusqr.com/landing/$user[$DBNav]';\" width=\"110\" align=\"left\" bgcolor=\"$color\"><img src=\"http:\/\/bonusqr.com\/fotos\/negocio$n.jpg\" width=\"80\" class=\"bordecomerciomini\"></td>
  154.          <td id=\"tablalink\" onclick=\"document.location.href='http://bonusqr.com/landing/$user[$DBNav]';\" bgcolor=\"$color\"><span class=\"rojo\">$user[$DBPromo] en $user[$DBComercio]<br>
  155.            </span>$user[$DBCondiciones]</td>
  156.        </tr>";
  157.     }
  158.  
  159.    if ($userid!=undef) {last};
  160.  };
  161. };
  162.  
  163. print "</table>
  164.      </div>
  165.  </tr>
  166. </table>
  167. </br></br>";
  168. do 'footer.cgi';
  169. close(USERS);
  170.  
  171.  
  172.  
Coloreado en 0.005 segundos, usando GeSHi 1.0.8.4
globalworkteam
Perlero nuevo
Perlero nuevo
 
Mensajes: 14
Registrado: 2012-04-17 20:26 @893

Siguiente

Volver a Básico

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 31 invitados

cron