davef101
02-10-2006, 09:16 PM
I'm trying to split a list of results into several result 'pages'.
i'm searching through a flat text file, picking out keywords.
but the problem i have, is i want to display only 25 results per page .. of a max of 100 results ..
i want the script to check the amount of results, then work out how many pages are needed, then automatically have links at the bottom of each page to the next list of results .. ie 1-25 .. 26-30 .. 31-45 etc ..
Any ideas ???
Thanks in advance.
script so far ..
#!/usr/bin/perl
$filename = "pricefiles/PriceFile.db";
local(@pairs,$pair,$val,$pos, $i);
if ($ENV{'REQUEST_METHOD'} eq "GET") {
$in = $ENV{'QUERY_STRING'};
}
elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN, $in, $ENV{'CONTENT_LENGTH'}+1);
}
$i = 0;
@pairs = split(/&/, $in);
foreach $pair (@pairs) {
# do the special character conversion
$pair =~ tr/+/ /;
$pair =~ s/%(..)/pack("c",hex($1))/ge;
$pos = index($pair,"=");
$name = substr($pair,0,$pos);
$val = substr($pair,$pos+1);
$i++;
$entry{$name} = $val;
}
############################################################
#
open(FILE,"$filename");
@lines = <FILE>;
foreach $line (@lines) {
chomp($line);
($P,$D,$PR,$MU) = split(/\|/,$line);
$LineCount++;
$PartNumber[$LineCount] = $P;
$PartDesc[$LineCount] = $D;
$PartPrice[$LineCount] = $PR;
$PartMarkup[$LineCount] = $MU;
}
close(FILE);
$entry{'selectManufacturer'} =~ tr/a-z/A-Z/;
$entry{'showModels'} =~ tr/a-z/A-Z/;
############################################################
#
print "Content-type: text/html\n\n";
open(FILE,"denso_sparkplugs/$entry{'selectManufacturer'}.txt");
@lines = <FILE>;
foreach $line (@lines) {
chomp($line);
($a,$b,$c,$d,$e,$f,$g,$h,$i) = split(/\|/,$line);
$lineNo++;
$model[$lineNo] = $a;
$cc[$lineNo] = $b;
$type[$lineNo] = $c;
$kw[$lineNo] = $d;
$engine[$lineNo] = $e;
$year[$lineNo] = $f;
$iridium[$lineNo] = $g;
$power[$lineNo] = $h;
$tough[$lineNo] = $i;
}
$lineNo = 0;
$found="";
foreach $line (@lines) {
# increment line counter
$lineNo++;
# does this line contain the term?
if ($line =~ /$entry{'showModels'}/) {
print <<End;
$entry{'selectManufacturer'} | $model[$lineNo] | $cc[$lineNo] | $type[$lineNo] | $kw[$lineNo] | $engine[$lineNo] | $year[$lineNo] | $iridium[$lineNo] | $power[$lineNo] | $tough[$lineNo] <BR><BR>
End
}
}
i'm searching through a flat text file, picking out keywords.
but the problem i have, is i want to display only 25 results per page .. of a max of 100 results ..
i want the script to check the amount of results, then work out how many pages are needed, then automatically have links at the bottom of each page to the next list of results .. ie 1-25 .. 26-30 .. 31-45 etc ..
Any ideas ???
Thanks in advance.
script so far ..
#!/usr/bin/perl
$filename = "pricefiles/PriceFile.db";
local(@pairs,$pair,$val,$pos, $i);
if ($ENV{'REQUEST_METHOD'} eq "GET") {
$in = $ENV{'QUERY_STRING'};
}
elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN, $in, $ENV{'CONTENT_LENGTH'}+1);
}
$i = 0;
@pairs = split(/&/, $in);
foreach $pair (@pairs) {
# do the special character conversion
$pair =~ tr/+/ /;
$pair =~ s/%(..)/pack("c",hex($1))/ge;
$pos = index($pair,"=");
$name = substr($pair,0,$pos);
$val = substr($pair,$pos+1);
$i++;
$entry{$name} = $val;
}
############################################################
#
open(FILE,"$filename");
@lines = <FILE>;
foreach $line (@lines) {
chomp($line);
($P,$D,$PR,$MU) = split(/\|/,$line);
$LineCount++;
$PartNumber[$LineCount] = $P;
$PartDesc[$LineCount] = $D;
$PartPrice[$LineCount] = $PR;
$PartMarkup[$LineCount] = $MU;
}
close(FILE);
$entry{'selectManufacturer'} =~ tr/a-z/A-Z/;
$entry{'showModels'} =~ tr/a-z/A-Z/;
############################################################
#
print "Content-type: text/html\n\n";
open(FILE,"denso_sparkplugs/$entry{'selectManufacturer'}.txt");
@lines = <FILE>;
foreach $line (@lines) {
chomp($line);
($a,$b,$c,$d,$e,$f,$g,$h,$i) = split(/\|/,$line);
$lineNo++;
$model[$lineNo] = $a;
$cc[$lineNo] = $b;
$type[$lineNo] = $c;
$kw[$lineNo] = $d;
$engine[$lineNo] = $e;
$year[$lineNo] = $f;
$iridium[$lineNo] = $g;
$power[$lineNo] = $h;
$tough[$lineNo] = $i;
}
$lineNo = 0;
$found="";
foreach $line (@lines) {
# increment line counter
$lineNo++;
# does this line contain the term?
if ($line =~ /$entry{'showModels'}/) {
print <<End;
$entry{'selectManufacturer'} | $model[$lineNo] | $cc[$lineNo] | $type[$lineNo] | $kw[$lineNo] | $engine[$lineNo] | $year[$lineNo] | $iridium[$lineNo] | $power[$lineNo] | $tough[$lineNo] <BR><BR>
End
}
}