The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
pagination displaying same results for all links
I have pagination code working properly for count and no of pages and limit. When I click on 2nd 3rd and 4rth pages same results are displayed. Can anybody please explain what am I missing
I really appreciate any help. Code starts here..... $limit = 2 ; $count = $db->query_first("select count(*) count query"); $count['count'] = vb_number_format($count['count']); $totalrows = $count['count']; if(empty($page)) { $page = 1; } $limitvalue = $page * $limit - ($limit); $query = "My query"; $getusercats = $db->query_read($query); while($cats = mysql_fetch_array($getcats)){ eval('$cats .= "' . fetch_template('mainforum_navpage') . '";'); } //Start pagination code here // by default we show first page $pageNum = 1; // if $_GET['page'] defined, use it as page number if(isset($_GET['page'])) { $pageNum = $_GET['page']; } if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $pagenum = intval($page); if (!isset($pagenum)) { $pagenum = 1; } // counting the offset $offset = ($pageNum - 1) * $limit; $numrows = $count['count']; // how many pages we have when using paging? $maxPage = ceil($numrows/$limit); // print the link to access each page $self = $_SERVER['PHP_SELF']; $nav = ''; for($page = 1; $page <= $maxPage; $page++) { if ($page == $pageNum) { $nav .= " $page "; // no need to create a link to current page } else { $nav .= " <a href=\"$self?page=$page\">$page</a> "; } } 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 = ' '; // we're on page one, don't print previous link $first = ' '; // nor the first page link } 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 = ' '; // we're on the last page, don't print next link $last = ' '; // nor the last page link } |
#2
|
|||
|
|||
Try to replace your first query
PHP Code:
PHP Code:
|
#3
|
|||
|
|||
Thanks for reply but count is not a problem. It is displaying correct number of pages and when we set limit to 10 Query is displaying all results correctly. If I have limit 2, records are displaying for 1st page and same records for all links. I am just wondering it is not going back to php page for next page results. The url is saying page=2,page=3... but the contents are 1st page results only.
Where am i doing wrong? Can any body please help me? Thanks |
#4
|
|||
|
|||
Is your query that is displaying the data when the user define page contain at the end LIMIT $first_record, $perpage. It should look something like this.
PHP Code:
|
#5
|
|||
|
|||
Yes, I have Limit $limitvalue limit in my query. The count is displaying correctly and also query because when I set the limit =20, all the results are displaying with just 1 page with no link to page. When I set Limit to 5 count of pages are displaying correct with all links,but the records are first 5 records for all pages when I click on 2nd,3rd,4th. The url link says page=2,3 correctly but results are only first page results.
Can you please tell me where am i doing wron. In my template I use $nav for pagination Here is my code with query also. $limit = 2 ; $count = $db->query_first("select count(*) as 'count' FROM forum AS forum LEFT JOIN user AS user ON (forum.userid = user.userid) where user.usergroupid='6'"); $count['count'] = vb_number_format($count['count']); $totalrows = $count['count']; if(empty($page)) { $page = 1; } $limitvalue = $page * $limit - ($limit); $query = "select forum.* ,user.* FROM forum AS forum LEFT JOIN user AS user ON (forum.userid = user.userid) where user.usergroupid='6' order by forum.forumid DESC LIMIT $limitvalue,$limit"; $getusercats = $db->query_read($query); while($usercats = mysql_fetch_array($getusercats)){ eval('$usercategories .= "' . fetch_template('mainforum_usercats_navpage') . '";'); } //Start pagination code here // by default we show first page $pageNum = 1; // if $_GET['page'] defined, use it as page number if(isset($_GET['page'])) { $pageNum = $_GET['page']; } // counting the offset $offset = ($pageNum - 1) * $limit; $numrows = $count['count']; // how many pages we have when using paging? $maxPage = ceil($numrows/$limit); // print the link to access each page $self = $_SERVER['PHP_SELF']; $nav = ''; for($page = 1; $page <= $maxPage; $page++) { if ($page == $pageNum) { $nav .= " $page "; // no need to create a link to current page } else { $nav .= " <a href=\"$self?page=$page\">$page</a> "; } } 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 = ' '; // we're on page one, don't print previous link $first = ' '; // nor the first page link } 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 = ' '; // we're on the last page, don't print next link $last = ' '; // nor the last page link } $db->free_result($usercats); eval('$home[$mods[\'modid\']][\'content\'] = "' . fetch_template('mainforum_usercats') . '";'); I appreciate your reply. |
#6
|
|||
|
|||
Replace
PHP Code:
PHP Code:
|
#7
|
|||
|
|||
MOT3rror I tried with code that you suggested. No affect on my page. The results are same for all page links. I am thinking we need to change something in this below line to get next page results from php page in addition to page=$page in pages links
$nav .= " <a href=\"$self?page=$page\">$page</a> "; Any suggestions.Please help me. Thanks for all your replies. |
#8
|
|||
|
|||
Sorry I see my error. It was checking to see if $page had a value and when it did it would make $page = 1 so change isset at the top to empty. Hopefully that makes it works. The code should be the following.
PHP Code:
|
#9
|
|||
|
|||
Thanks for your effort. I changed code to empty. But no change. Still displaying same results for all pages.
I changed in query also to $query = "select forum.* ,user.* FROM forum AS forum LEFT JOIN user AS user ON (forum.userid = user.userid) where user.usergroupid='6' order by forum.forumid DESC LIMIT " . ($limitlower - 1) . ", $limit"; Any other suggestions Thanks |
#10
|
|||
|
|||
This article can show you a way to do pagination with vBulletin functions.
https://vborg.vbsupport.ru/showthrea...t=page+results |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|