So with my code below im really stumped on whats happening. I've looking on the internet and looked at a bunch of code and it seems to be similar to mine but i have no clue why mine isnt working. when you click on the next(or any page) link it just displays an empty page. it might be a really simple solution or just a dumb mistake on my part on the code but i just cant figure out whats happening.
<?php
mysql_connect ("localhost", "root","root") or die (mysql_error());
mysql_select_db ("FHSNL");
//sets all values in form to php variables
$surname = $_GET['surname'];
$given = $_GET['given'];
$maiden = $_GET['maiden'];
$deathdate = $_GET['death'];
$deathrange = $_GET['range'];
$deathbefore = $_GET['death'] - $deathrange;
$deathafter = $_GET['death'] + $deathrange;
$age = $_GET['age'];
$birth = $_GET['birth'];
$birthplace = $_GET['birthplace'];
$deathplace = $_GET['deathplace'];
$erected = $_GET['erected'];
$region = $_GET['region'];
$religion = $_GET['religion'];
//divides into smaller sql pieces for filled in form input.
if($surname)$piece[] .= "`SURNAME` LIKE '%$surname%'";
if($given)$piece[] .= "`GIVEN` LIKE '%$given%'";
if($maiden)$piece[] .= "`MAIDEN` LIKE '%$maiden%'";
if($age)$piece[] .= "`AGE` LIKE '%$age%'";
if($deathplace)$piece[] .= "`PLACE_OF_DEATH` LIKE '%$deathplace%'";
if($region)$piece[] .= "`TOWN` LIKE '%$region%'";
if($religion)$piece[] .= "`RELIGION` LIKE '%$religion%'";
if($deathdate)$piece[] .= "`YEAR_OF_DEATH` BETWEEN '$deathbefore' AND '$deathafter'";
//if submit button is pressed it runs the search query.
//echo "Matthew";
//if(isset($_GET['submit'])){
echo $surname;
if (isset($_GET['pn']) && is_numeric($_GET['pn'])) {
// cast var as int
$currentpage = (int) $_GET['pn'];
} else {
// default page num
$pn = 1;
} // end if
if(isset($piece)){
$sqlend = implode(" AND ",$piece);
$sql = mysql_query("SELECT * FROM `HEADSTONESA` WHERE $sqlend");
$rows = mysql_num_rows($sql);
$page_rows = 25;
$last = ceil($rows / $page_rows);
if($pn < 1)
{
$pn = 1;
}
elseif($pn > $last)
{
$pn = $last;
}
$max = " LIMIT " .($pn - 1) * $page_rows .",". $page_rows;
$sql_p = mysql_query("SELECT * FROM `HEADSTONESA` WHERE $sqlend $max") or die(mysql_error());
//constructs the table.
echo "<table><tr><th>ID</th><th>Plot Number</th><th>Given</th><th>Surname</th><th>Cemetery</th><th>Region</th><th>Town</th><th>Date of Death</th><th>Age</th><th>Date of Birth</th><th>Place of Birth</th><th>Place of Death</th><th>Erected By</th><th>Additional Info</th></tr>";
$k = 0;
while($row = mysql_fetch_array($sql_p))
{
if($k % 2 == 0){
echo '<tr class = "tdeven">';
echo "<td>" .$row['ID'] . "</td>";
echo '<td><a href = "profile.php?pnum='.$row['ID'].'">'. $row['PLOT_NO'] . '</a></td>';
echo "<td>".$row['GIVEN']."</td>";
echo "<td>".$row['SURNAME']."</td>";
$requested_id = $row['KEYS'];
$town_id = $row['TOWN'];
$region_id = $row['REGION'];
$sql2 = mysql_query("SELECT * FROM `CEMETERIES` WHERE `KEYS` LIKE '$requested_id'");
$row2 = mysql_fetch_array($sql2);
echo "<td>".$row2['NAME']."</td>";
echo "<td>".$row2['REGION']."</>";
echo "<td>".$row2['TOWN']."</td>";
echo "<td>".$row['D_OF_DEATH']."</td>";
echo "<td>" .$row['AGE']. "</td>";
echo "<td>" .$row['D_OF_BIRTH']."</td>";
echo "<td>" .$row['PLACE_OF_BIRTH']."</td>";
echo "<td>" .$row['PLACE_OF_DEATH']."</td>";
echo "<td>" .$row['ERECTED_BY']."</td>";
echo "<td>" .$row['ADD_INFO']."</td>";
echo "</tr>";
echo "</div>";
}
else{
echo '<tr class = "tdodd">';
echo "<td>" .$row['ID'] . "</td>";
echo '<td><a href = "profile.php?pnum='.$row['ID'].'">'. $row['PLOT_NO'] . '</a></td>';
echo "<td>".$row['GIVEN']."</td>";
echo "<td>".$row['SURNAME']."</td>";
$requested_id = $row['KEYS'];
$town_id = $row['TOWN'];
$region_id = $row['REGION'];
$sql2 = mysql_query("SELECT * FROM `CEMETERIES` WHERE `KEYS` LIKE '$requested_id'");
$row2 = mysql_fetch_array($sql2);
echo "<td>".$row2['NAME']."</td>";
echo "<td>".$row2['REGION']."</>";
echo "<td>".$row2['TOWN']."</td>";
echo "<td>".$row['D_OF_DEATH']."</td>";
echo "<td>" .$row['AGE']. "</td>";
echo "<td>" .$row['D_OF_BIRTH']."</td>";
echo "<td>" .$row['PLACE_OF_BIRTH']."</td>";
echo "<td>" .$row['PLACE_OF_DEATH']."</td>";
echo "<td>" .$row['ERECTED_BY']."</td>";
echo "<td>" .$row['ADD_INFO']."</td>";
echo "</tr>";
echo "</div>";}
$k++;
}
echo "</table>";
echo " --Page $pn of $last-- ";
// First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.
if ($pn == 1)
{
}
else
{
echo "<a href='{$_SERVER['PHP_SELF']}?pn=1'><<-First</a> ";
echo " ";
$previous = $pn-1;
echo "<a href='{$_SERVER['PHP_SELF']}?pn=$previous'> <-Previous</a> ";
}
//just a spacer
echo " -- " .$pn ." -- ";
if ($pn == $last)
{
}
else {
$next = $pn+1;
echo "<a href='{$_SERVER['PHP_SELF']}?pn=$next'>Next -></a> ";
echo " ";
echo "<a href='{$_SERVER['PHP_SELF']}?pn=$last'>Last ->></a> ";
}
//if nothing found prints out the following.
if(!$rows)
echo "No results where found";
}
//}
//if no search terms entered prints the following.
?>
Thanks for the help