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