mmarif4u Posted June 30, 2007 Share Posted June 30, 2007 Hi guys. I have a little problem in pagination of searching script. The following are the form code: <form method='get' action=''> <input type='text' name='search'> <input type='submit' name='submit' value='Search'> </form> The following are the php code for searching: <?php if($_GET['submit']){ $rowsPerPage= 10; $pageNum = 1; if(isset($_GET['page'])) { $pageNum = $_GET['page']; } $offset = ($pageNum - 1) * $rowsPerPage; echo "Results"; echo '<br>'; $sql2="select * from courses_add where courses_add like '%$search%' LIMIT $offset, $rowsPerPage "; $select2=mysql_query($sql2); $numrows2=mysql_num_rows($select2); echo "Your search keyword return ".$numrows2." results"; echo '<br>';echo '<br>'; $query_count = "SELECT COUNT(*) AS page_count_rows FROM courses_add where courses_add like '%$search%'"; $result_count = mysql_query($query_count) or die(mysql_error()); $row_count = mysql_fetch_array($result_count, MYSQL_ASSOC); $page_count_rows = $row_count['page_count_rows']; $maxPage = ceil($page_count_rows/$rowsPerPage); if($maxPage>200){ $maxPage = 200; } $self = $_SERVER['PHP_SELF']; $nav_page = ''; while($row2=mysql_fetch_object($select2)){ $term1=$row2->courses_add; $c_id=$row2->c_id; echo $term1; echo '<br>'; } } ?> <br> <?php if ($page_count_rows>10){ ?> <table align="center" border="0" cellpadding="0" cellspacing="0" width="95%"> <tr> <td><hr noshade color="#6699FF" align="left" width="100%" size="1"> </td> </tr> <tr> <td align="center"> <?php include('paging.php'); ?> </td> </tr> </table><br> <?php } ?> Now the problem is if click the next link suppose it have to go to 2nd page, it works but i did not see any data there. I work out on this last night but no luck. Can any one give some helpful hints. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
sasa Posted June 30, 2007 Share Posted June 30, 2007 can we see paging.php Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted June 30, 2007 Author Share Posted June 30, 2007 Yes sure: <?php // creating 'previous' and 'next' link // plus 'first page' and 'last page' link // print 'previous' link only if we're not // on page one 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 = '<font size="2" face="verdana"> [Prev] </font>'; // we're on page one, don't enable 'previous' link $first = '<font size="2" face="verdana"> [First Page] </font>'; // nor 'first page' link } // print 'next' link only if we're not // on the last 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 = '<font size="2" face="verdana"> [Next] </font>'; // we're on the last page, don't enable 'next' link $last = '<font size="2" face="verdana"> [Last Page] </font>'; // nor 'last page' link } // print the page navigation link //echo $first . $prev . $nav . $next . $last; echo $first . $prev . "<font size='2' face='verdana'> Showing page </font><strong><font color='blue'>$pageNum</font></strong><font size='2' face='verdana'> of </font><strong><font color='blue'>$maxPage</font></strong><font size='2' face='verdana'> pages </font></strong></font>" . $next . $last; ?> Quote Link to comment Share on other sites More sharing options...
sasa Posted June 30, 2007 Share Posted June 30, 2007 on 2nd page you don't have $_GET['submit'] change paging.php to $page = $pageNum + 1; $next = " <a href=\"$self?page=$page&submit=Search&search=$search\">[Next]</a> "; $last = " <a href=\"$self?page=$maxPage&submit=Search&search=$search\">[Last Page]</a> "; Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted June 30, 2007 Author Share Posted June 30, 2007 Thanks mate. It works like a charm. Quote Link to comment 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.