Jump to content

search form with pagination Help


MasonPrice

Recommended Posts

i need some help.....im using a basic form with pagination, but it does not seem to be working for some reason it displays the username i search for the first time but when i click on the next button i get no more results even though i have like 30 more results left in the database ........... any help would be appriciated thanks in advance

 

 

Here is the code i am using

 

<?php include ('connect.php'); ?>
<?php
echo"<h3>Please enter your search Username</h3>
<form action='search.php?find' method='post'>
<input name='username' size='40'  maxlength='32'/>				
<input type='submit' value='Submit' />
</form>";
?>
<hr width="800">               

<?php                
  
if (isset($_GET["find"]))
{	
$username =  ($_POST["username"]);

$per_page =5;

$start = @$_GET['start'];

$record_count = mysql_num_rows(mysql_query("SELECT * FROM register WHERE username LIKE '%$username%' ORDER BY username"));

$max_pages = $record_count / $per_page; 

if(!$start)
  $start = 0;

$query = mysql_query("SELECT * FROM register WHERE username LIKE '%$username%'ORDER BY username LIMIT $start, $per_page ");
$exist = mysql_num_rows($query); 

if($exist=='0')
{
	echo "No match found";
}
else 
{
	echo "Your matches for: <b>$username</b><br><br>";
	while($currow = mysql_fetch_array($query))
	{
$username = ($currow['username']);
   

echo"</td>
  </tr>
</table>";
?>



<?php echo"
        <a href='../mysite/$username'>$username</a><br>" ;

	}
}

	?>

<?php
$prev = $start - $per_page;
$next = $start + $per_page;

echo"<br>";
if(!($start<=0))
echo "<a href='{$_SERVER['PHP_SELF']}?start=$prev'>Prev</a> ";

$i=1;
for($x=0;$x<$record_count;$x=$x+$per_page)
{
if($start!=$x)
echo "<a href='{$_SERVER['PHP_SELF']}?start= $x'>$i</a> ";
else
   echo "<a href='{$_SERVER['PHP_SELF']}?start= $x'>$i</a> ";
$i++;
}

if(!($start>=$record_count-$per_page))
echo "<a href='{$_SERVER['PHP_SELF']}?start=$next'>Next</a>";
echo" $next";
echo"<br><br>";
}
?>

</div>
</body>
</html>
<?php include ('footer.php'); ?>


Link to comment
Share on other sites

Post can only be sent from forms. The easiest way to get your pagination working is to append the username to the url.

 

Change the form to GET and add the username to the page links...

<form action='search.php?find' method='get'> 

 

then

echo "<a href='{$_SERVER['PHP_SELF']}?start=$prev&username=$_GET['username']'>Prev</a> ";

etc.

Link to comment
Share on other sites

i have made the changes you suggested with a little of my own changes to the form but i still do not get any results to pass to the next page  ?????? Any one else has any idea your help would be appreciated................................. thanks in advance

 

<?php include ('connect.php'); ?>
<?php
echo"<h3>Please enter your search Username</h3>

<form action='search.php' method='get'>
<input name='username' size='40'  maxlength='32'/>
<input type='submit' name="submit" value='Submit' />
</form>";
?>
<hr width="800">               
<?php                
  
if (isset($_GET["submit"]))
{
$username =  ($_GET["username"]);

$per_page =5;

$start = @$_GET['start'];

$record_count = mysql_num_rows(mysql_query("SELECT * FROM register WHERE username LIKE '%$username%' ORDER BY username"));

$max_pages = $record_count / $per_page; 

if(!$start)
  $start = 0;

$query = mysql_query("SELECT * FROM register WHERE username LIKE '%$username%'ORDER BY username LIMIT $start, $per_page ");
$exist = mysql_num_rows($query); 

if($exist=='0')
{
echo "No match found";
}
else 
{
echo "Your matches for: <b>$username</b><br><br>";
while($currow = mysql_fetch_array($query))
{
$username = ($currow['username']);
?>

<?php echo"<a href='../mysite/$username'>$username</a><br>" ;
}
}
?>

<?php
$prev = $start - $per_page;
$next = $start + $per_page;

echo"<br>";
if(!($start<=0))
echo "<a href='{$_SERVER['PHP_SELF']}?start=$prev&username=$username'>Prev</a> ";
$i=1;
for($x=0;$x<$record_count;$x=$x+$per_page)
{
if($start!=$x)
echo "<a href='{$_SERVER['PHP_SELF']}?start=$x&$username=$username'>$i</a>"; 
else
echo "<a href='{$_SERVER['PHP_SELF']}?start=$x&username=$username'>$i</a> ";
$i++;
}
if(!($start>=$record_count-$per_page))
echo "<a href='{$_SERVER['PHP_SELF']}?start=$next&username=$username'>Next</a>";
echo" $next";
echo"<br><br>";
}
?>

</div>
</body>
</html>
<?php include ('footer.php'); ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.