TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 05-16-2009, 09:22 PM   #1 (permalink)
The Visitor
 
Join Date: May 2009
Posts: 4
Thanks: 0
builtfoxy is on a distinguished road
Default admin/categories/page nav

Can anyone help me with page navigation for my admin/categories page.The code now is:

php Code:
function listCategories($option){
    global $database;
   
    $database->setQuery( "SELECT c.* FROM #__adsmanager_categories as c ".
                         "WHERE 1 ORDER BY c.parent,c.ordering");
    $rows = $database->loadObjectList();
    if ($database -> getErrorNum()) {
        echo $database -> stderr();
        return false;

    }
   
    require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
        $pageNav = new mosPageNav( $total, $limitstart,$limit );


                        
    // establish the hierarchy of the menu
    $children = array();
    // first pass - collect children
    foreach ($rows as $v ) {
        $pt     = $v->parent;
        $list   = @$children[$pt] ? $children[$pt] : array();
        array_push( $list, $v );
        $children[$pt] = $list;
    }
   
    HTML_adsmanager::listcategories($option, count($rows),$children,$pageNav);
}

And Joomla page nav says to code as follows:

To retrieve this two params you can use the following lines

$limit        = intval( mosGetParam( $_REQUEST, 'limit', 0 ) );
$limitstart = intval( mosGetParam( $_REQUEST, 'limitstart', 0 ) );

You can put this two lines on the beginning of your component since it is commonly used by all routines that handle database.

Next step is to find out how many rows will be returned by the query on which you intend to implement paging.

php Code:
$query = "SELECT COUNT(id) FROM #__users";
$database->setQuery( $query );
$total = $database->loadResult();

Now we must make sure that we set $limit and $limitstart variables in case they haven't been set yet.

php Code:
$limit = $limit ? $limit : 15;
if ( $total <= $limit ) {
    $limitstart = 0;
}

The first line sets the $limit to 15 if it hasn't been set yet. That means 15 items per page. User can change this number later using a drop-down box.
The second line sets the $limitstart to 0 in case that total number of items is less than $limit variable, insuring that something will be displayed if the $limitstart is greater than max.

Now we must include pageNavigation.php and create mosPageNav object.

php Code:
require_once( $GLOBALS['mosConfig_absolute_path'] . '/includes/pageNavigation.php' );
$pageNav = new mosPageNav( $total, $limitstart, $limit );

Then execute a real query with all fields we need to display our items, and pass $limitstart and $limit to $database object.

php Code:
$query = "SELECT id. name, username, email FROM #__users";
$database->setQuery( $query, $limitstart, $limit );
$rows = $database -> loadObjectList();
       
for( $i=0; $i<count($rows); $i++ )
{
    $row = $rows[$i];
    echo $row->name." / ".$row->username." / ".$row->email."<br>";
}

This will write all users on current page to client browser.

To draw paging we use the following code.

html4strict Code:
<div style="position: relative; float: left;">
           
            <div style="float: right;">Display #
                    <?php
                        echo $pageNav->
getLimitBox( $link );
                    ?>
            </div>
           
            <div style="float: left;">
                <?php
                    echo $pageNav->
writePagesLinks( $link );
                ?>
            </div>
       
        </div>
       
        <div style="position: relative; float: left;">
            <?php
                echo $pageNav->
writePagesCounter();
            ?>
</div>

This last piece of code can be rearranged, so you can fit it to your component the way you like it.


Can anyone help me place the joomla code in the right position.

Thanks Glenn absolute newbie!!

Last edited by Wildhoney : 05-16-2009 at 11:43 PM.
builtfoxy is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design