vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   [How To] Paginate Admin CP Results (https://vborg.vbsupport.ru/showthread.php?t=200413)

Iain M 01-01-2009 10:00 PM

[How To] Paginate Admin CP Results
 
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.

Vaupell 02-07-2009 10:56 PM

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.

Iain M 02-24-2009 04:41 PM

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?


All times are GMT. The time now is 11:31 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.03442 seconds
  • Memory Usage 1,771KB
  • 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
  • (1)bbcode_code_printable
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete