MasonPrice Posted November 20, 2010 Share Posted November 20, 2010 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'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/219259-search-form-with-pagination-help/ Share on other sites More sharing options...
harristweed Posted November 20, 2010 Share Posted November 20, 2010 The username is not set the for the second page, because it is not posted. Quote Link to comment https://forums.phpfreaks.com/topic/219259-search-form-with-pagination-help/#findComment-1137035 Share on other sites More sharing options...
MasonPrice Posted November 21, 2010 Author Share Posted November 21, 2010 i know its not posted can you show me how to posted please Quote Link to comment https://forums.phpfreaks.com/topic/219259-search-form-with-pagination-help/#findComment-1137343 Share on other sites More sharing options...
harristweed Posted November 21, 2010 Share Posted November 21, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/219259-search-form-with-pagination-help/#findComment-1137455 Share on other sites More sharing options...
MasonPrice Posted November 22, 2010 Author Share Posted November 22, 2010 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'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/219259-search-form-with-pagination-help/#findComment-1137712 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.