JTable/move

This Article Needs Your Help

This article is tagged because itNEEDS REVIEW. You can help the Joomla! Documentation Wiki by contributing to it.More pages that need help similar to this one are here.NOTE-If you feel the need is satistified, please remove this notice.

Syntax

Parameters

Additional where query to limit ordering to a particular subset of records

Returns

nothing

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 move down the entry 'Hello' one step.

//We need an instance of the table object. In a controller or model we can do it like this...$table=$this->getTable('greeting');//We need to load the 'Hello' entry into the table object. The id (which is the primary key of the table) of this entry is 1.$table->load(1);//We now want to move the 'Hello' entry one step down. That means, the $dirn Parameter must be positive.//We choose the value 1, but it could also be any other positive number$table->move(1);

The first thing the method does is to load the record which has the next higher ordering value. (If our $dirn paremeter would have been negative, it would have loaded the record with the next lower ordering value. In our case, this is the record with the id #4.

id

greeting

ordering

4

Buenos Días

10

The next (and last step) is that the method switches the ordering values of both records.

Content is available under Joomla! EDL unless otherwise noted.Joomla!® is a registered trademark of Open Source Matters, Inc.If you are experiencing technical issues with this website, please report it
.
Notice a content problem? Create an account
and fix it.