TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   admin/categories/page nav (http://www.talkphp.com/absolute-beginners/4308-admin-categories-page-nav.html)

builtfoxy 05-16-2009 09:22 PM

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!!

builtfoxy 05-19-2009 11:51 PM

What did i do , post if the wrong forum!!!
 
Can anyone help or do i need to look elsewhere?

Wildhoney 05-20-2009 01:44 AM

Lots and lots of code to look through. Let me have a look :-) !

Wildhoney 05-20-2009 01:45 AM

Is this a mod then for Joomla, but you don't know where to place the code?

builtfoxy 05-20-2009 02:33 AM

Yes it is a joomla component, Adsmanager. I do not know where to place the code.I tried it in a few different positions and blinked out the page.Thanks for your responce.

Glenn

builtfoxy 05-28-2009 11:43 PM

Where did you go?
 
Quote:

Originally Posted by builtfoxy (Post 24441)
Yes it is a joomla component, Adsmanager. I do not know where to place the code.I tried it in a few different positions and blinked out the page.Thanks for your responce.

Glenn

Wildhoney have you looked into that code?


All times are GMT. The time now is 02:12 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0