This code displays the first record in the limit query but when I click "next", the page is updated but no record is displayed.All the bits of code work independently, but now that I have got them together!!! classic problem. No error message is displayed.
Code:
<?PHP
include 'config.php';
include 'opendb.php';
$page_name = 'update_form01.php'; // If you use this code with a different page ( or file ) name then change this
//create search form,
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
Enter First Name:-<INPUT NAME="FirstName" TYPE="TEXT" id="FirstName" size="50" maxlength="50"><br>
Enter Surname:-<INPUT NAME="SurName" TYPE="TEXT" id="SurName" size="50" maxlength="50"><br>
<INPUT TYPE="SUBMIT" NAME="Search" id="SUBMIT" VALUE="Search">
</FORM>
<?PHP
$queryItem = array();
///create the start variable that will chage when the link is clicked
$start =(isset($_GET['start']))?$_GET['start']:0;
$eu = ($start);
$limit = 1; // No of records to be shown per page.
$this_one = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;
if(isset($_POST['Search']))
{
if ($_POST['FirstName'])
{
$queryItem[] = "FirstName='".mysql_escape_string($_POST['FirstName'])."'";
}
if ($_POST['SurName'])
{
$queryItem[] = "SurName='".mysql_escape_string($_POST['SurName'])."'";
}
if ($_POST['Postcode'])
{
$queryItem[] = "Postcode='".mysql_escape_string($_POST['Postcode'])."'";
}
//////////////////////////now create query statement
$query1 = "SELECT * FROM Addressbook
WHERE ".implode(" AND ", $queryItem)
or die(mysql_error());
$result1 = mysql_query($query1) or die(mysql_error());
$nume = mysql_num_rows($result1) or die(mysql_error());
/////// The variable nume above will store the total number of records in the query////
////////////// Now let us start executing the query with variables $eu and $limit set at the top of the page///////////
$query = "SELECT * FROM Addressbook
WHERE ".implode(" AND ", $queryItem)."
LIMIT $eu, $limit "
or die(mysql_error());
$result = mysql_query($query) or die(mysql_error());
// get the entry from the result
// Print out the contents
while($row = mysql_fetch_array($result))
{
echo $row['FirstName']." ".$row['SurName'];
echo"<br>";
echo $row['Address1']." ".$row['Address2']." ".$row['Address3'];
echo"<br>";
echo $row['Town']." ".$row['Postcode'];
echo"<br>";
echo "<em><strong>E-Mail:-</em></strong>"." ".$row['email'];
echo"<br>";
echo "<em><strong>Phone:-</em></strong>"." ".$row['Phone'];
echo"<p></P>";
}
echo "<br>";
}
////////////////////////////// End of displaying the table with records ////////////////////////
/////////////// Start the buttom links with Prev and next link with page numbers /////////////////
echo "<table align = 'center' width='50%'><tr><td align='left' width='30%'>";
//// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
if($back >0)
{
print "<a href='$page_name?start=$back'>PREV</a>";
}
echo "</td><td align='right' width='30%'>";
///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
if($this_one < $nume)
{
print "<a href='$page_name?start=$next'>NEXT</a>";
}
echo "</td></tr></table>";
?>