< API16:JTable

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.


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.


getNextOrder($where= '')
Parameter Name Default Value Description
$where WHERE clause to use for selecting the MAX(ordering) for the table.


mixed Boolean false an failure or the next ordering value as an integer.

Defined in



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.
                'SELECT MAX(ordering)' .
                ' FROM `'.$this->_tbl.'`' .
        $max = (int) $this->_db->loadResult();

        // Check for a database error.
        if ($this->_db->getErrorNum()) {
                return false;

        // Return the largest ordering value + 1.
        return ($max + 1);


Code Examples