Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'd be grateful for some pointers as to where I've gone wrong so that I can get the results#!c:\perl\bin\perl.exe use strict; use warnings; use DBI; use CGI; my $q=new CGI; my %sm = $q->Vars(); my $word = $sm{concordance}; print $q->header(); print $q->start_html(-title=>'Dickens Concordance'); print qq[<form method="post"action="/cgi-bin/view.pl" name="concordanc +e">]; #code to create the scroll down box which selects from the db my $db = DBI->connect('dbi:mysql:lit:localhost', 'user', 'pw', {RaiseError => 1, AutoCommit => 1}); my $sth = $db->prepare("SELECT DISTINCT word FROM dickens"); $sth->execute; my @data; while (my @result = $sth->fetchrow_array) { push @data,$result[0]; } print $q->scrolling_list(-name=>"concordance", -value=>\@data, - +size=>30); $sth->finish; $db->disconnect(); print $q->submit(-value=>"Choose"); print qq[</form>]; #Count number of lines in db $db = DBI->connect('dbi:mysql:lit:localhost', 'user', 'pw'); my $row = $db->selectrow_arrayref('SELECT COUNT(*) FROM dickens'); my $count = $row->[0]; my $Page_Size = "50"; my $first = $q->param("start") || 1; my $last = $first + $Page_Size - 1; $last = $count if $last > $count; #Query the db my $results = $db->selectall_arrayref('SELECT word ,line FROM dickens +WHERE word="$concordance" LIMIT 50'); for (my $i=$first; $i<= $last; $i++) { my $user = $results->[$i-1]; printf("%d <br />\n", $i, $user); } #Create the next and previous pages my $prev_rec = $first - $Page_Size; $prev_rec = 1 if $prev_rec < 1; my $prev_link = sprintf('%s/%d', url(-full => 1), $prev_rec); my $next_rec = $last + 1; my $next_link = sprintf('%s/%d', url(-full => 1), $next_rec); if ($first == 1) { print "Previous"; } else { printf('<a href="%s">Previous</a>', $prev_link); } print "|"; if ($next_rec < $count) { printf('<a href="%s">Next</a>', $next_link); } else { print "Next"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Viewing data one page at a time
by roboticus (Chancellor) on Feb 29, 2008 at 14:47 UTC | |
|
Re: Viewing data one page at a time
by spatterson (Pilgrim) on Feb 29, 2008 at 15:59 UTC |