vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   pagination displaying same results for all links (https://vborg.vbsupport.ru/showthread.php?t=166138)

reddyink 12-26-2007 12:22 AM

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 = '&nbsp;'; // we're on page one, don't print previous link
$first = '&nbsp;'; // 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 = '&nbsp;'; // we're on the last page, don't print next link
$last = '&nbsp;'; // nor the last page link
}

MoT3rror 12-26-2007 05:21 AM

Try to replace your first query
PHP Code:

 $count $db->query_first("select count(*) count query"); 

with
PHP Code:

 $count $db->query_first("select count(*) AS 'count' FROM table"); 


reddyink 12-26-2007 01:42 PM

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

MoT3rror 12-26-2007 07:22 PM

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:

$query $db->query_read("SELECT * FROM table LIMIT $limitlower$perpage"); // $limitlower is the first record that is showed. 

while($data $db->fetch_array($query))
{
//Output data here



reddyink 12-26-2007 09:00 PM

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 = '&nbsp;'; // we're on page one, don't print previous link
$first = '&nbsp;'; // 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 = '&nbsp;'; // we're on the last page, don't print next link
$last = '&nbsp;'; // nor the last page link
}

$db->free_result($usercats);
eval('$home[$mods[\'modid\']][\'content\'] = "' . fetch_template('mainforum_usercats') . '";');

I appreciate your reply.

MoT3rror 12-26-2007 09:44 PM

Replace
PHP Code:

if(empty($page))
{
$page 1;
}
$limitvalue $page $limit - ($limit); 

with

PHP Code:

if (isset($page)
{
    
$page 1;
}

//Default lower and upper limit variables
  
$limitlower = ($page 1) * $limit 1;
  
$limitupper $page $limit;

    if (
$limitupper $count['count'])
    {
   
//Too many for upper limit
          
$limitupper $count['count'];
        if (
$limitlower $count['count'])
         {
            
//Too many for lower limit
             
$limitlower $count['count'] - $limit;
         }
      }
        if (
$limitlower <= 0)
     {
      
//Can't have negative or null lower limit
       
$limitlower 1;
   } 

Or you can read this article which will should a way to use vBulletin functions to create a pagination. https://vborg.vbsupport.ru/showthrea...t=page+results

reddyink 12-26-2007 10:23 PM

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.

MoT3rror 12-26-2007 10:31 PM

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:

if (empty($page)
{
    
$page 1;
}

//Default lower and upper limit variables
  
$limitlower = ($page 1) * $limit 1;
  
$limitupper $page $limit;

    if (
$limitupper $count['count'])
    {
   
//Too many for upper limit
          
$limitupper $count['count'];
        if (
$limitlower $count['count'])
         {
            
//Too many for lower limit
             
$limitlower $count['count'] - $limit;
         }
      }
        if (
$limitlower <= 0)
     {
      
//Can't have negative or null lower limit
       
$limitlower 1;
   } 


reddyink 12-26-2007 10:53 PM

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

MoT3rror 12-26-2007 10:56 PM

This article can show you a way to do pagination with vBulletin functions.
https://vborg.vbsupport.ru/showthrea...t=page+results


All times are GMT. The time now is 10:03 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01169 seconds
  • Memory Usage 1,775KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete