Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pagination problem

Status
Not open for further replies.

scitech

Technical User
Jan 6, 2005
40
GB
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>";

?>
 
Hi Woody
The line 16 is the session_start()
Code:
if(isset($_POST['Search']))
{
    session_start();
    unset ($_SESSION);
    $_SESSION = $_POST;
}
 
Did you have any output before line 16? Like empty space or any enter character?
 
Hi woody
basically I copied your code straight across, just to see what would happen!. So I have no output before the session_start(). Just the two includes and the $page_name = 'update_form01.php'.
I have read that session_start() must come at the very beginning of the page code.
So I moved session_start()to the first line, to see what would happen:- the same error message with the line number changed for the new position.
On my page I have all the standard HTML code, head,body etc, should not make a difference?
 
session_start() must be executed before any other output on the page. That means before any html, before any echoes or prints and even spaces or carriage returns before the opening <?php tag. You should inspect if you have any of those and remove them if necessary.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top