#!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[
]; #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[
]; #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
\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('Previous', $prev_link); } print "|"; if ($next_rec < $count) { printf('Next', $next_link); } else { print "Next"; }