API16

JTable/getNextOrder

From Joomla! Documentation

< API16:JTable
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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.

Description[edit]

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[edit]

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

Returns[edit]

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

Defined in[edit]

libraries/joomla/database/table.php

Importing[edit]

jimport( 'joomla.database.table' );

Source Body[edit]

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[edit]

Code Examples[edit]