noobstar Posted December 23, 2006 Share Posted December 23, 2006 Hi everyone :)This is a fairly simple problem but i can't seem to see it anywhere grrr. What this does is display the first 5 results and then has a Next, Last etc link on the bottom so you can view the other results.However, this displays the 5 results and doesn't show the Next, Last etc links on the bottom. Its probably something i forgot to convert when i copied this from my working example.If someone could just take a quick look at the code below and maybe work it out please let me know :)Here is the code:[code]<?phpinclude ("/home/btk/public_html/forum/config.php");$search = $_POST['search'];// how many rows to show per page$rowsPerPage = 5;// by default we show first page$pageNum = 1;// if $_GET['page'] defined, use it as page numberif(isset($_GET['page'])){ $pageNum = $_GET['page'];}// counting the offset$offset = ($pageNum - 1) * $rowsPerPage;$query = "select * from fusion_users where user_name like '%$search%' LIMIT $offset, $rowsPerPage";$result = mysql_query($query) or die('Error, query failed');echo "<div align=center><span class=style1><u>Search Results</u></span>";while($row = mysql_fetch_array($result)){echo "<br/><br/><form method=post style=display:inline action=#>";echo "<input type=submit value='".$row['user_name']."' class=link>";echo "<input type=hidden name=user_name value='".$row['user_name']."'></form>";}// how many rows we have in database$query = "SELECT COUNT(user_id) as numrows from fusion_users where user_name like '%$search%'";$result = mysql_query($query) or die('Error, query failed');$row = mysql_fetch_array($result, MYSQL_ASSOC);$numrows = $row['numrows'];// how many pages we have when using paging?$maxPage = ceil($numrows/$rowsPerPage);$self = $_SERVER['PHP_SELF'];// creating 'previous' and 'next' link// plus 'first page' and 'last page' link// print 'previous' link only if we're not// on page oneif ($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] '; // we're on page one, don't enable 'previous' link $first = ' [First Page] '; // nor 'first page' link}// print 'next' link only if we're not// on the last pageif ($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] '; // we're on the last page, don't enable 'next' link $last = ' [Last Page] '; // nor 'last page' link}echo "<br/><br/><a href=viewpage.php?page_id=2>Back</a></div>";?><style type="text/css"><!--.style1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; font-size: 14px;}.link { background:none; border:none; cursor:pointer; color:black; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px;}--></style>[/code]Thank you very much for any replies :) Quote Link to comment https://forums.phpfreaks.com/topic/31659-solved-paged-query-issue/ Share on other sites More sharing options...
Jessica Posted December 23, 2006 Share Posted December 23, 2006 Where are you printing the next and last variables via echo? Shouldn't it be after you set them, somewhere you need to print them to the screen? You set them and then check a link to back, but nothing else? Quote Link to comment https://forums.phpfreaks.com/topic/31659-solved-paged-query-issue/#findComment-146752 Share on other sites More sharing options...
noobstar Posted December 23, 2006 Author Share Posted December 23, 2006 Yea i just realized it myself lol was about to post that i solved it a min ago hahaThx for the reply though ;) Quote Link to comment https://forums.phpfreaks.com/topic/31659-solved-paged-query-issue/#findComment-146755 Share on other sites More sharing options...
Jessica Posted December 23, 2006 Share Posted December 23, 2006 Good job :) Don't forget to hit the solved button ;) Quote Link to comment https://forums.phpfreaks.com/topic/31659-solved-paged-query-issue/#findComment-146756 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.