Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Viewing

by Kiko (Scribe)
on Aug 16, 2000 at 22:01 UTC ( #28162=perlquestion: print w/ replies, xml ) Need Help??
Kiko has asked for the wisdom of the Perl Monks concerning the following question:

Hey, I left this program alone for a while and now i'm working on it again. I'm trying to view the first 100 records from a database and then display the next 100 and so on. I'm able to display the first 100 but i don't know how to show the next 100. This is the section of my program that's supposed to do this: my ($row)=0; my ($count)=0; my ($min)=0; my ($max)=$min+100; while ($db->FetchRow()) { if(($row>=$min)&&($row<$max)) { my (%dbrow) = $db->DataHash(); $dbrow{'details'}=substr($dbrow{'details'},0,50); print<<HERE_HTML_ROW; <td bgcolor="$recordbg"><font face="arial" size="1">$dbrow{'la +stname'},&nbsp;$dbrow{'firstname'}&nbsp;</font>&nbsp;</td> <td bgcolor="$recordbg"><font face="arial" size="1">$dbrow{'of +ficephonenumber'}&nbsp;</font>&nbsp;</td> <td bgcolor="$recordbg"><font face="arial" size="1">$dbrow{'de +scription'}&nbsp;</font>&nbsp;</td> <td bgcolor="$recordbg"><font face="arial" size="1">$company_t +ype&nbsp;</font>&nbsp;</td> <td bgcolor="$recordbg"><font face="arial" size="1">$dbrow{'co +mpany_name'}&nbsp;</font>&nbsp;</td> <td bgcolor="$recordbg"><font face="arial" size="1">$dbrow{'de +tails'}&nbsp;</font>&nbsp;</td> HERE_HTML_ROW print "\n</tr>\n"; } $row++; $count++; } print "\n</table>\n"; my ($visible); if ($count>=$max){ $visible=$max; } else { $visible=$count; } print<<HERE_HTML; <BR><font size="2" face="helvetica"><B>1-$visible of $count records di +splayed</B></font> HERE_HTML # This is the part that's not working because i don't think # that i can do this, please help. if ($row>$max) { print "<font size=2 face=helvetica><a href=\"$ENV{'SCRIPT_NAME'}?$ +ENV{'QUERY_STRING'}&min=100\">Next 100</a></font>\n"; } Thanks, Kiko

Comment on Viewing
Download Code
Re: Viewing the first 100 records, then the next 100.
by Kiko (Scribe) on Aug 16, 2000 at 22:09 UTC
    The title for this post should have been: Viewing the first 100 records, then the next 100. Sorry about that.
RE: Viewing
by merlyn (Sage) on Aug 16, 2000 at 22:21 UTC
Re: Viewing
by Kiko (Scribe) on Aug 17, 2000 at 01:08 UTC
    Is there anohter way to go about this other than using session ids?
      You have to have some way to correlate one hit with the next. The easiest way is with a session ID that you hold in a hidden field, mangled URL, cookie, basic-auth, or mangled hostname.

      -- Randal L. Schwartz, Perl hacker

Re: Viewing
by Speedfreak (Sexton) on Aug 17, 2000 at 12:00 UTC

    Hejsan

    This was asked before and a good answer was given but I cant remember the author so you'll have to search it.

    The proposed solutions was how I would of done it - do it via SQL.

    You can use the LIMIT keyword to show a subset of the data returned. For example:

    SELECT * FROM mydata LIMIT 100,100;
    

    Here, it tells it to show from the 100th record (1st number) and only 100 records (2nd).

    I would approach it by making your "next" link append the next number for limit. Pseudo code may look something like:

    my $blocksize = 100; my $limit = 1 + param("limit"); #get the value from the query stri +ng my $sql = "SELECT * FROM data LIMIT $limit,$blocksize;"
    Then your next and back buttons may have links like:
    showdata.pl?limit=200
    showdate.pl?limit=0
    

    Add garnish as desired...

    - Jed

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://28162]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2014-11-27 18:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (187 votes), past polls