hello, i am having problem with my pagination. i can pass the user input to the next page. any1 can help me? i dont know how to do it. <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php include "dbconnect.php"; $link=dbconnect(); $pc = $_POST['pc']; $rowsPerPage = 4; $pageNum = 1; if(isset($_GET['page'])) { $pageNum = $_GET['page']; } $offset = ($pageNum - 1) * $rowsPerPage; $query = "select *from doctors WHERE pc='$pc' "; $pagingQuery = "LIMIT $offset, $rowsPerPage"; $result = mysql_query($query . $pagingQuery) or die('Error, query failed'); $columns_counter=0; while($row = mysql_fetch_array( $result )) { echo "cus name:"; echo $row['name']; } $columns_counter++; if($columns_counter==6){ $columns_counter=0; } echo '<br><BR>'; $result = mysql_query($query) or die('Error, query failed'); $numrows = mysql_num_rows($result); $maxPage = ceil($numrows/$rowsPerPage); $self = $_SERVER['PHP_SELF']; if ($pageNum > 1) { $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page\">[Prev]</a> "; $first = " <a href=\"$self?page=1\">[First Page]</a> "; } else { $prev = ' [Prev] '; $first = ' [First Page] '; } if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " <a href=\"$self?page=$page\">[Next]</a> "; $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> "; } else { $next = ' [Next] '; $last = ' [Last Page] '; } echo $first . $prev . " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages " . $next . $last; ?> </body> </html> when i click onto the next button it cant retrieve any information. I think i m not able to pass user input. can any1 help me? i don know how to do it.
The problem with your code is at: $pc = $_POST['pc']; When you click the next button, $pc will have no value and the result of your query is becomming empty. To fix that, use get in your form instead of post method and add the $pc to the navigation urls such as the $next and $prev. so your form would be something like: <form name="form1" method="get" action=""> and your php code would be something like: $prev = " <a href=\"$self?page=$page&pc=$pc\">[Prev]</a> "; $first = " <a href=\"$self?page=1&pc=$pc\">[First Page]</a> "; Also don't forget to have $pc = $_GET['pc']; instead of $pc = $_POST['pc']; I hope that helps. Good Luck