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!

paginate a search problem

Status
Not open for further replies.

scitech

Technical User
Jan 6, 2005
40
GB
The problem is that when I add a form to start a search the pagination stops working it displays the first page, the correct number of pages but on clicking next page it shows a blank page. The pager class works fine,but when I add
Code:
if ($_POST['SurName'] )
{
$queryItem = 'SurName="'.mysql_escape_string($_POST['SurName']).'"';
}
to the page it all starts to go wrong!!!.Even though on the following code nothing is passed from the form at all!
Code:
<?php

include 'config.php';
include 'opendb.php';
include ("pager.class");


?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
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
if ($_POST['SurName'] )
{
$queryItem = 'SurName="'.mysql_escape_string($_POST['SurName']).'"';
}

	if($queryItem)
	{
	/* Instantiate class */

	$p = new Pager;

	/* Show many results per page? */
	$limit = 1;

	/* Find the start depending on $_GET['page'] (declared if it's null) */
	$start = $p->findStart($limit);
	/* Find the number of rows returned from a query; Note: Do NOT use a LIMIT clause in this query */
	$query = "SELECT * FROM $table_name";
	echo $query."<br>";
	$result = mysql_query($query) or die(mysql_error());
	$count = mysql_num_rows($result) or die(mysql_error());
	echo "<br>".$count."<br>";
	/* Find the number of pages based on $count and $limit */
	$pages = $p->findPages($count, $limit);

	/* Now we use the LIMIT clause to grab a range of rows */
	$result = mysql_query("SELECT * FROM $table_name LIMIT ".$start.", ".$limit);

	/* Now get the page list and echo it */
	$pagelist = $p->pageList($_POST['page'], $pages);
	echo $pagelist;

	/* Or you can use a simple "Previous | Next" listing if you don't want the numeric page listing */
	//$next_prev = $p->nextPrev($_GET['page'], $pages);
	//echo $next_prev;

	/* From here you can do whatever you want with the data from the $result link. */
	 while($row = mysql_fetch_array($result))
		{
        echo "<br>".$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>";
        };
	}

	else echo "Please enter a search!";	
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top