Dave, you were right but there is another problem. Here's the entire code.
#/usr/bin/perl -w
use strict;
use DBI;
use CGI qw(:standard);
use POSIX qw(ceil floor);
my $LastName=param('LastName');
my $reqpage= param('reqpage');
unless ($reqpage > 1) {$reqpage = "1";
&count;
}
if ($reqpage > 1) {
&search;
}
sub count {
my $dbh = DBI->connect('dbi:mysql:membersdb','member','memberpass
+wd')
or die "Connection Error: $DBI::errstr\n";
# Count how many rows are there in a table, so that we can use it
+for $pagenum.
my $LastName=param('LastName');
my $n="3";
my $LastName= substr($LastName,0,$n);
my $query="$LastName\%";
my $sql = "select count(*) from members WHERE (Location = 'Phoenix
+, AZ USA' and LastName LIKE ?)";
my $sth = $dbh->prepare ("$sql");
$sth->execute($query) || quit();
my $result_count = $sth->fetchrow_array;
$sth->finish;
my $pagesize = "5";
if ($result_count != 0) {
my $pagecount = int($result_count / $pagesize);
if (($pagecount * $pagesize) != $result_count) {
$pagecount++;
}
$sth->finish;
$dbh->disconnect ();
&search;
sub search {
my $dbh = DBI->connect('dbi:mysql:membersdb','member','memberpass
+wd')
or die "Connection Error: $DBI::errstr\n";
my $reqpage= param('reqpage');
unless ($reqpage > 1) {$reqpage = "1";}
my $pagesize = "5";
my $firstresult = (($reqpage - 1) * $pagesize) + 1;
my $lastresult = $firstresult + $pagesize - 1;
if ($lastresult > $result_count) {
$lastresult = $result_count;
}
my $offset = (($reqpage-1) * $pagesize);
my $limit = "5";
my $result;
my @result;
my $LastName=param('LastName');
my $n="3";
my $LastName= substr($LastName,0,$n);
my $query="$LastName%";
my $sql = "Select AccountID,LastName,FirstName,Location,Specialty,Intr
+oduction,View from members WHERE (Location = 'Phoenix, AZ USA' and La
+stName LIKE ?) Limit $offset,$limit";
my $sth=$dbh->prepare("$sql");
$sth->execute($query) or die "Connection Error: $DBI::errstr\n";
print header(), start_html;
my $page = "E:/companyname/website/htdocs/resources/header_1.htm";
open (PAGE, "$page") || die "Couldn't open $page";
while (<PAGE>) {print;}
print "<br><p align=\"center\"><font size=\"5\"><b> <u>Your
+ Search Results</u></b></font><br><br>";
while (my @results = $sth->fetchrow_array)
{
my $AccountID = $results [0];
my $LastName = $results [1];
my $FirstName = $results [2];
my $Location = $results [3];
my $Specialty = $results [4];
my $Introduction = $results [5];
my $View = $results [6];
my $Image = $results [0];
print <<"(END TABLE HTML)";
<center>
<Table width="700" style="border-collapse: collapse;border: 1px solid
+#000000" bordercolor="#111111">
<tr><td width="90" valign="top"><img src="http://www.website.com/resou
+rces/$Image" height="100" width=100" alt = "No Image Available"></td>
+<td align="left"><p align=\"left\"><font size=\"4\"><ul><li><b>Name&n
+bsp;---- $FirstName $LastName</b><br>Location ----&nbs
+p;$Location<br>
Specialty ---- $Specialty<br><br>$Introduction<br><br>$View<
+/li></ul></font></p>
</td></tr></table>
(END TABLE HTML)
##++$count;
}
my $prev_page;
my $next_page;
my $prev_link;
my $next_link;
my $pagelinks;
my $pageno;
my $thislink;
my $pagesize = "5";
$prev_page = $reqpage - 1;
$next_page = $reqpage + 1;
if ($reqpage == 1) {
$prev_link = "";
} else {
$prev_link = "<a href=\search_test14.pl?reqpage=$prev_page>Previous</a
+> ";
}
if ($reqpage == $pagecount) {
$next_link = "";
} else {
$next_link = "<a href=\search_test14.pl?reqpage=$next_page>NEXT</a>";
}
if ($pagecount > 1) {
$pagelinks = $prev_link;
$pageno = 0;
while ($pageno < $pagecount) {
$pageno++;
if ($pageno == $reqpage) {
$thislink = " <b>$pageno</b> ";
} else {
$thislink = "<a href=\search_test14.pl?reqpage=$pageno>$pageno</a>&nbs
+p;"
}
$pagelinks = $pagelinks . $thislink;
}
$pagelinks = $pagelinks . " " . $next_link;
print "<br><p align=\"center\"><font size=\"3\">$pagelinks</font></p>"
+;
} else {
$pagelinks = "";
}
}
print <<"(END FOOTER HTML)";
<head>
<title>FOOTER</title>
</head>
<body topmargin="0" leftmargin="0" rightmargin="0">
<table width="800">
<tr>
<td width="800"><p align="left"><a href="http://www.diversitylink.com"
+>Home</a></p>
</td>
</tr>
<tr>
<td width="100%">
<img src="http://www.website.com/images/blk.gif" height="1" widt
+h="100%"></td>
</tr>
</table>
<table width="800" cellpadding="0"><tr><td width="100%"><p align="cent
+er"><font size="1" face="Arial">
© My Company<br>
All Rights Reserved<br></font></td>
</tr></table>
(END FOOTER HTML)
end_html ();
$sth->finish;
$dbh->disconnect ();
}
}
exit;
I am trying to get results from a table in the MySQL database and show 5 results per page. The initial search does just that having determined the correct number of pages required, and shows links 1-2-3-etc-Next on the bottom of the page. However when page 2, 3, or Next are called the $Name value is ignored and everything in the column 'Location' is counted again and everything is presented with the correct number(5 rows) per page. Why is the name value being ignored?? Help Please!!!