Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
[How To] Paginate Admin CP Results
Iain M's Avatar
Iain M
Join Date: Jul 2005
Posts: 256

 

Glasgow, Scotland
Show Printable Version Email this Page Subscription
Iain M Iain M is offline 01-01-2009, 10:00 PM

Had just finished developing a hack, and realized over time that the pages in the admin cp would become quite long if they weren't paginated, so I ventured into the modcp/banning.php file to help me out...

This article is for hack authors, and presumes you are familiar with vBulletin and PHP in general.

First block of code...
PHP Code:
    $vbulletin->input->clean_array_gpc('r', array(
        
'pagenumber'   => TYPE_UINT,
    ));

    
$perpage 25;//number of results per page
    
if(!$vbulletin->GPC['pagenumber']){
        
$vbulletin->GPC['pagenumber'] = 1;
    }
    
$start = ($vbulletin->GPC['pagenumber'] - 1) * $perpage;

    
//count the number of rows
    
$rewardscount $db->query_first("
        SELECT COUNT(*) AS count
        FROM " 
TABLE_PREFIX "table_name
    "
);    
        
    
$pagecount ceil($rewardscount['count'] / $perpage); 
Things to change are the $perpage variable, the table_name.

Then the output of the pagination...
PHP Code:
        if($pagecount 1){
            
$pagenav "<strong>$vbphrase[go_to_page]</strong>";
            for (
$thispage 1$thispage <= $pagecount$thispage++){
                if(
$thispage == $vbulletin->GPC['pagenumber']){
                    
$pagenav .= " <strong>[$thispage]</strong> ";
                } else {
                    
$pagenav .= " <a href=\"incent_admin.php?$session[sessionurl]do=rewards&amp;page=$thispage\" class=\"normal\">$thispage</a> "//your admin cp page and do=
                
}
            }

            
print_description_row($pagenavfalse4'''right'); //change 4 to your colspan
        

Here you have to change incent_admin.php to your filename and the do=, and the 4 in the print_description_row.

Then there's your query:
PHP Code:
        $getrewards $db->query_read("
            SELECT rewardid, name, points, cost
            FROM " 
TABLE_PREFIX "table_name
            ORDER BY rewardid ASC
            LIMIT 
$start$perpage            
        "
); 
All you just need to add to your query is the LIMIT $start, $perpage.

If you've done it correctly you should have page navigation on your admin cp page.


Here's the code in full from one of my pages, if you don't understand anything above:
PHP Code:
    $vbulletin->input->clean_array_gpc('r', array(
        
'pagenumber'   => TYPE_UINT,
    ));

    
$perpage 25;
    if(!
$vbulletin->GPC['pagenumber']){
        
$vbulletin->GPC['pagenumber'] = 1;
    }
    
$start = ($vbulletin->GPC['pagenumber'] - 1) * $perpage;

    
$rewardscount $db->query_first("
        SELECT COUNT(rewardid) AS count
        FROM " 
TABLE_PREFIX "incent_rewards
    "
);    
        
    
$pagecount ceil($rewardscount['count'] / $perpage);
        
    
print_table_start();
    
print_table_header("Incent Rewards"40'''center'0);
    echo 
'<tr><td align="center" class="thead">Reward</td>';
    echo 
'<td align="center" class="thead">Points Required</td>';
    echo 
'<td align="center" class="thead">Cost</td>';    
    echo 
'<td align="center" class="thead">Info</td></tr>';
        if(
$pagecount 1){
            
$pagenav "<strong>$vbphrase[go_to_page]</strong>";
            for (
$thispage 1$thispage <= $pagecount$thispage++){
                if(
$thispage == $vbulletin->GPC['pagenumber']){
                    
$pagenav .= " <strong>[$thispage]</strong> ";
                } else {
                    
$pagenav .= " <a href=\"incent_admin.php?$session[sessionurl]do=rewards&amp;page=$thispage\" class=\"normal\">$thispage</a> ";
                }
            }

            
print_description_row($pagenavfalse4'''right');
        }
        
$getrewards $db->query_read("
            SELECT rewardid, name, points, cost
            FROM " 
TABLE_PREFIX "incent_rewards
            ORDER BY rewardid ASC
            LIMIT 
$start$perpage            
        "
);
            while(
$reward $db->fetch_array($getrewards)){
                
$cell[1] .= "<a href=\"incent_admin.php?do=edit_reward&rewardid=$reward[rewardid]\">$reward[name]</a>";
                
$cell[2] .= "$reward[points]";
                
$cell[3] .= "$reward[cost]";
                
$cell[4] .= "<a href=\"incent_admin.php?do=reward_stats&rewardid=$reward[rewardid]\">Stats</a> / <a href=\"incent_admin.php?do=edit_reward&rewardid=$reward[rewardid]\">Edit</a> / <a onclick=\"return confirm('Are you sure you want to delete this reward?');\" href=\"incent_admin.php?do=delete_reward&rewardid=$reward[rewardid]\">Delete</a>";
        
                
print_cells_row($cell);
                unset(
$cell);
            }
            
    echo 
'<tr><td align="center" class="alt1" colspan="4"><a style="font-weight: bold;" href="incent_admin.php?do=add_reward">Add Reward</a></td></tr>';        
    
print_table_footer(4''''0); 
(Phrases are hard coded coz the hack is just for my own use, for now)


Also, thanks to Revan for his [How-To] Paginate your results for user pages.
Reply With Quote
  #2  
Old 02-07-2009, 10:56 PM
Vaupell's Avatar
Vaupell Vaupell is offline
 
Join Date: Apr 2008
Location: Esbjerg, Denmark
Posts: 1,036
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Awsome TX....

5x stars


EDIT :
Im haveing problems with linking to pages..

The problem is, linking from pagenavs
and the one that lists my query is DO Find
and when i change the pagenav to fit the links to the other pages fail

Code:
$pagenav .= " <a href=\"sh2.php?$session[sessionurl]do=Find&amp;page=$thispage\" class=\"normal\">$thispage</a> ";


and find is the one printing results, and works fine, only shows the ammount i
set it for, howewer when clicking additional pages, it goes blank just as if it cant
located the requested destination..

any suggestions ? Im confused where the link goes, i can see it goes to do=find but the rest page=X
heh nope.
Reply With Quote
  #3  
Old 02-24-2009, 04:41 PM
Iain M's Avatar
Iain M Iain M is offline
 
Join Date: Jul 2005
Location: Glasgow, Scotland
Posts: 256
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry for the late reply... don't come on here often.

Would you mind PM'ing me your file, and I'll take a look at it?
Reply With Quote
Reply


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 06:55 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.03914 seconds
  • Memory Usage 2,261KB
  • Queries Executed 18 (?)
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)bbcode_code
  • (4)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (3)post_thanks_box
  • (1)post_thanks_box_bit
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (3)post_thanks_postbit_info
  • (2)postbit
  • (3)postbit_onlinestatus
  • (3)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_postinfo_query
  • fetch_postinfo
  • 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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete