API16:JTable/getNextOrder
From Joomla! Documentation
Description
Method to get the next ordering value for a group of rows defined by an SQL WHERE clause. This is useful for placing a new item last in a group of items in the table.
Syntax
getNextOrder($where= '')
| Parameter Name | Default Value | Description |
|---|---|---|
| $where | WHERE clause to use for selecting the MAX(ordering) for the table. |
Returns
mixed Boolean false an failure or the next ordering value as an integer.
Defined in
libraries/joomla/database/table.php
Importing
jimport( 'joomla.database.table' );
Source Body
public function getNextOrder($where = '')
{
// If there is no ordering field set an error and return false.
if (!property_exists($this, 'ordering')) {
$this->setError(get_class($this).' does not support ordering');
return false;
}
// Prepare the WHERE clause if set.
$where = ($where) ? ' WHERE '.$where : '';
// Get the largest ordering value for a given where clause.
$this->_db->setQuery(
'SELECT MAX(ordering)' .
' FROM `'.$this->_tbl.'`' .
$where
);
$max = (int) $this->_db->loadResult();
// Check for a database error.
if ($this->_db->getErrorNum()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
// Return the largest ordering value + 1.
return ($max + 1);
}
Examples
Code Examples