Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 12-26-2007, 12:22 AM
reddyink reddyink is offline
 
Join Date: Aug 2007
Posts: 236
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
}
Reply With Quote
  #2  
Old 12-26-2007, 05:21 AM
MoT3rror MoT3rror is offline
 
Join Date: Mar 2007
Posts: 423
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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"); 
Reply With Quote
  #3  
Old 12-26-2007, 01:42 PM
reddyink reddyink is offline
 
Join Date: Aug 2007
Posts: 236
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #4  
Old 12-26-2007, 07:22 PM
MoT3rror MoT3rror is offline
 
Join Date: Mar 2007
Posts: 423
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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

Reply With Quote
  #5  
Old 12-26-2007, 09:00 PM
reddyink reddyink is offline
 
Join Date: Aug 2007
Posts: 236
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #6  
Old 12-26-2007, 09:44 PM
MoT3rror MoT3rror is offline
 
Join Date: Mar 2007
Posts: 423
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #7  
Old 12-26-2007, 10:23 PM
reddyink reddyink is offline
 
Join Date: Aug 2007
Posts: 236
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #8  
Old 12-26-2007, 10:31 PM
MoT3rror MoT3rror is offline
 
Join Date: Mar 2007
Posts: 423
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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;
   } 
Reply With Quote
  #9  
Old 12-26-2007, 10:53 PM
reddyink reddyink is offline
 
Join Date: Aug 2007
Posts: 236
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #10  
Old 12-26-2007, 10:56 PM
MoT3rror MoT3rror is offline
 
Join Date: Mar 2007
Posts: 423
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:01 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07879 seconds
  • Memory Usage 2,279KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete