Actions

Difference between revisions of "JTable/reorder"

From Joomla! Documentation

(New page: ===Syntax=== ''void'' reorder ([string $where = '']) where: {| class="wikitable" !Argument !Data type !Description !Default |- |$where |string |Additional where query to limit ordering...)
 
Line 44: Line 44:
 
$table = $this->getTable('greeting');
 
$table = $this->getTable('greeting');
 
//Let's compact the ordering sequence
 
//Let's compact the ordering sequence
$table->reorder;
+
$table->reorder();
 
</source>
 
</source>
 +
The first thing the method does is to load the table ordered by the current ordering:
 +
{| class="wikitable"
 +
!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:
 +
{| class="wikitable"
 +
!id
 +
!greeting
 +
!ordering
 +
|-
 +
|3
 +
|Guten Tag
 +
|1
 +
|-
 +
|1
 +
|Hello
 +
|2
 +
|-
 +
|2
 +
|Bonjour
 +
|3
 +
|}
  
 
===See also===
 
===See also===
* [http://api.joomla.org/Joomla-Framework/Document/JDocument.html#getMetaData JDocument->getMetaData on api.joomla.org]
+
* [[JTable/move]]
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JDocument]]</noinclude>
+
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JTable]]</noinclude>

Revision as of 01:40, 7 November 2008

Contents

Syntax

void reorder ([string $where = ])

where:

Argument Data type Description Default
$where string Additional where query to limit ordering to a particular subset of recordsgetDescription or getGenerator respectively.

Preconditions

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

What does the method do?

The goal of the method is to compact the ordering sequence of the selected records. To do this, the method loads all records of the table (or just those that have been defined in the 'where'-clause. It then resets the ordering of all records in such a way that the ordering is continious.

Example

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

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

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