W
webmaster
Thanks to everyone here, I am closer to getting this working but am
still having a problem....
The script runs and outputs a page, but in the db I have set up all of
the categories have enough entries to fill multiple pages. So, the
script runs and always goes to page 2 for some reason.
And if I click on one of the other links for a different page, then I
get nothing on that one.
Can anyone spot the problem?
Thanks in advance,
Jim
#!/usr/bin/perl -w
use DBI;
use CGI;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use CGI qwstandard);
use POSIX;
use HTML::Template;
use strict;
use diagnostics;
my $limit;
my $q = new CGI;
my $find = $q->param("search");
if (!$limit) {$limit = 5;}
my $dbname = "DBI:mysql:farthing_valleyweb:localhost";
my $dbusername = "farthing_farthin";
my $dbpassword = "ginajim";
my( $ID, $category, $name, $description, $contact, $phone, $fax,
$address, $city, $state, $zip, $email, $url, $keywords );
my $dbh = DBI->connect($dbname, $dbusername, $dbpassword)
or die ("Connection to database failed: $!\n");
my $sql = "select * from valley where category like ?";
my $sth = $dbh->prepare($sql) or die("Error in SQL1\n");
$sth->execute($find) or die "Error in SQL2 $!\n";
my $results = $sth->rows;
my $results_per_page = 5;
my $pagesrequired = ceil($results / $results_per_page);
my $sql = "select * from valley where category like ?
limit $limit, $results_per_page";
my $sth = $dbh->prepare($sql) or die("Error in SQL3\n");
$sth->execute($find) or die ("Error in SQL4\n");
$sth->bind_columns( \$ID, \$category, \$name, \$description, \
$contact, \$phone, \$fax, \$address, \$city, \$state, \$zip, \$email, \
$url, \$keywords );
while( $sth->fetch() ) {
print "<b>$name</b><br />
$phone<br />
$address<br />
$city, $state $zip<p />\n";
}
for (my $i = 0; $i <= $pagesrequired -1; $i++) {
if ($i == 0) {
if ($limit != 0) {
print "<a href=\"search.cgi?limit=0&find=$find\">";
print $i + 1;
print "</a>";
}
else {print $i + 1;}
}
if ($i > 0) {
if ($limit != ($i * $results_per_page)) {
print " | <a href=\"search.cgi?limit=";
print ($i * $results_per_page);
print "&find=$find\">\n";
print $i + 1, "</a>";
}
else {print " | ", $i + 1;}
}
}
still having a problem....
The script runs and outputs a page, but in the db I have set up all of
the categories have enough entries to fill multiple pages. So, the
script runs and always goes to page 2 for some reason.
And if I click on one of the other links for a different page, then I
get nothing on that one.
Can anyone spot the problem?
Thanks in advance,
Jim
#!/usr/bin/perl -w
use DBI;
use CGI;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use CGI qwstandard);
use POSIX;
use HTML::Template;
use strict;
use diagnostics;
my $limit;
my $q = new CGI;
my $find = $q->param("search");
if (!$limit) {$limit = 5;}
my $dbname = "DBI:mysql:farthing_valleyweb:localhost";
my $dbusername = "farthing_farthin";
my $dbpassword = "ginajim";
my( $ID, $category, $name, $description, $contact, $phone, $fax,
$address, $city, $state, $zip, $email, $url, $keywords );
my $dbh = DBI->connect($dbname, $dbusername, $dbpassword)
or die ("Connection to database failed: $!\n");
my $sql = "select * from valley where category like ?";
my $sth = $dbh->prepare($sql) or die("Error in SQL1\n");
$sth->execute($find) or die "Error in SQL2 $!\n";
my $results = $sth->rows;
my $results_per_page = 5;
my $pagesrequired = ceil($results / $results_per_page);
my $sql = "select * from valley where category like ?
limit $limit, $results_per_page";
my $sth = $dbh->prepare($sql) or die("Error in SQL3\n");
$sth->execute($find) or die ("Error in SQL4\n");
$sth->bind_columns( \$ID, \$category, \$name, \$description, \
$contact, \$phone, \$fax, \$address, \$city, \$state, \$zip, \$email, \
$url, \$keywords );
while( $sth->fetch() ) {
print "<b>$name</b><br />
$phone<br />
$address<br />
$city, $state $zip<p />\n";
}
for (my $i = 0; $i <= $pagesrequired -1; $i++) {
if ($i == 0) {
if ($limit != 0) {
print "<a href=\"search.cgi?limit=0&find=$find\">";
print $i + 1;
print "</a>";
}
else {print $i + 1;}
}
if ($i > 0) {
if ($limit != ($i * $results_per_page)) {
print " | <a href=\"search.cgi?limit=";
print ($i * $results_per_page);
print "&find=$find\">\n";
print $i + 1, "</a>";
}
else {print " | ", $i + 1;}
}
}