Actions

JTable/move

From Joomla! Documentation

Revision as of 03:08, 7 November 2008 by Batch1211 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Contents

Syntax

void move ($dirn, [$where = ])

where:

Argument Data type Description Default
$dirn integer Direction to move the record. $dirn < 0 for up, $dirn > 0 for down.
$where string Additional where query to limit ordering to a particular subset of records

Preconditions

Your database table must have a column named 'ordering'.

What does the method do?

The goal of the method is to move a record of the table one step up, or one step down by switching the ordering values with the respective neighbour.

Example

Let's say we have the following database-table:

id greeting ordering
1 Hello 5
2 Bonjour 15
3 Guten Tag 3
4 Buenos Días 10
5 Nǐ hǎo 17

We now want to compress the ordering of the table.

//We need an instance of the table object. In a controller or model we can do it like this...
$table = $this->getTable('greeting');
//Let's compact the ordering sequence
$table->reorder();

The first thing the method does is to load the table ordered by the current ordering:

id greeting ordering
3 Guten Tag 3
1 Hello 5
2 Bonjour 15

The next (and last step) is that the method updates the ordering entries so it's a consecutive sequence:

id greeting ordering
3 Guten Tag 1
1 Hello 2
2 Bonjour 3

See also

  • JTable/move