sub DoSearchActive { my $dbh = DBI->connect('DBI:mysql:new_db','username','password'); my $limit_3 = param("limit_3"); my $limit = param("limit"); $limit = ($limit_3 + $limit); my $spread = ($limit + 1); my $spread_2 = ($limit + 10); my $types = $dbh->selectrow_array('SELECT COUNT(status) FROM applicant WHERE status = "Active"'); if ($spread_2 >= $types){$spread_2 = $types} if ($spread >= $types){$spread = $types} print qq(

There are $types applications listed as 'Active'.
Results $spread - $spread_2 shown.

); print qq($table); print qq($table_headers); my $sth = $dbh->prepare('SELECT * FROM applicant WHERE status = "Active" ORDER BY date_col DESC LIMIT ?,10'); $sth->bind_param(1, $limit, DBI::SQL_INTEGER); $sth->execute($limit) or die $sth->errstr; while (my @result = $sth->fetchrow_array()) { if ($result[21] eq '' || $result[21] eq '0000-00-00') {$shade = $default} else {$shade = $default2} if ($result[32] eq 'checked') {$fav = $something} else {$fav = ''} print qq(

$result[20]$result[15]$result[16]$result[1], $result[2]$result[28]
$result[6]
$result[11]-$result[12]-$result[13]@result[17, 18, 19]$result[61]
$result[39]
$fav
$result[31]$result[62]$result[63]$result[64]$result[65]\n); } print qq(
); print qq(); if ($sth->rows == 0) { print qq(
There are no employees in the Active folder.\n\n); } $sth->finish(); $dbh->disconnect; &DoSomethingElse; }