Attention

TYPO3 v6 has reached its end-of-life April 18th, 2017 and is not maintained by the community anymore. Looking for a stable version? Use the version switch on the top left.

There is no further ELTS support. It is strongly recommended updating your project.

select

This object generates an SQL-select statement needed to select records from the database.

Some records are hidden or timed by start and end-times. This is automatically added to the SQL-select by looking in the $GLOBALS['TCA'] (enablefields).

Note: Be careful if you are using GET/POST data (for example GPvar) in this object! You could introduce SQL injections!

Always secure input from outside, for example with intval!

Property

uidInList

Data type

Until TYPO3 4.5: list of record_ids

Since TYPO3 4.6: list of record_ids /stdWrap

Description

Comma-separated list of record uids from the according database table. For example when the select function works on the table tt_content, then this will be uids of tt_content records.

Special keyword: "this" is replaced with the id of the current record.

Property

pidInList

Data type

list of page_ids /stdWrap

Description

Comma-separated list of pids of the record. This will be page_ids. For example when the select function works on the table tt_content, then this will be pids of tt_content records, the parent pages of these records.

Pages in the list, which are not visible for the website user, are automatically removed from the list. Thereby no records from hidden, timed or access-protected pages will be selected! Nor will be records from recyclers.

Special keyword: "this" is replaced with the id of the current page.

(Since TYPO3 6.2) Special keyword: "root" allows to select records from the root-page level (records with pid=0, e.g. useful for the table "sys_category" and others).

(Since TYPO3 6.2) Special value: "-1" allows to select versioned records in workspaces directly.

Example:

10 = CONTENT
10 {
  table = sys_category
  select {
    pidInList = root,-1
    selectFields = sys_category.*
    join = sys_category_record_mm ON sys_category_record_mm.uid_local = sys_category.uid
    where.data = field:_ORIG_uid // field:uid
    where.intval = 1
    where.wrap = sys_category_record_mm.uid_foreign=|
    orderBy = sys_category_record_mm.sorting_foreign
    languageField = sys_category.sys_language_uid
  }
}

This example fetches related sys_category records stored in the MM intermediate table.

Default

this

Property

recursive

Data type

integer /stdWrap

Description

Number of recursivity levels for the pidInList.

Default

0

Property

orderBy

Data type

SQL-orderBy /stdWrap

Description

ORDER BY clause without the words "ORDER BY".

Example:

orderBy = sorting, title

Property

groupBy

Data type

SQL-groupBy /stdWrap

Description

GROUP BY clause without the words "GROUP BY".

Example:

groupBy = CType

Property

max

Data type

Until TYPO3 4.5: integer +calc +"total"

Since TYPO3 4.6: integer +calc +"total" /stdWrap

Description

Max records

Special keyword: "total" is substituted with count(*).

Property

begin

Data type

Until TYPO3 4.5: integer +calc +"total"

Since TYPO3 4.6: integer +calc +"total" /stdWrap

Description

Begin with record number value.

Special keyword: "total" is substituted with count(*).

Property

where

Data type

Until TYPO3 4.5: SQL-where

Since TYPO3 4.6: SQL-where /stdWrap

Description

WHERE clause without the word "WHERE".

Example:

where = (title LIKE '%SOMETHING%' AND NOT doktype)

Property

andWhere

Data type

SQL-where /stdWrap

Description

AND clause in a WHERE clause; without the word "AND".

Example:

andWhere = NOT doktype

Property

languageField

Data type

Until TYPO3 4.5: string

Since TYPO3 4.6: string /stdWrap

Description

If set, this points to the field in the record which holds a reference to a record in sys_language table. And if set, the records returned by the select-function will be selected only if the value of this field matches the $GLOBALS['TSFE']->sys_language_uid (which is set by the option config.sys_language_uid).

Property

includeRecordsWithoutDefaultTranslation

Data type

Until TYPO3 7.2: boolean

Since TYPO3 7.3: boolean /stdWrap

Description

(Since TYPO3 6.2) If content language overlay is activated and the option "languageField" is set, includeRecordsWithoutDefaultTranslation allows to additionally fetch records, which do not have a parent in the default language.

Default

0

Property

selectFields

Data type

Until TYPO3 4.5: string

Since TYPO3 4.6: string /stdWrap

Description

List of fields to select, or "count(*)".

If the records need to be localized, please include the relevant localization-fields (uid, pid, languageField and transOrigPointerField). Otherwise the TYPO3 internal localization will not succeed.

Default

*

Property

join

leftjoin

rightjoin

Data type

Until TYPO3 4.5: string

Since TYPO3 4.6: string /stdWrap

Description

Enter the table name for JOIN, LEFT OUTER JOIN and RIGHT OUTER JOIN respectively.

Property

markers

Data type

(array of markers)

Description

The markers defined in this section can be used, wrapped in the usual ###markername### way, in any other property of select. Each value is properly escaped and quoted to prevent SQL injection problems. This provides a way to safely use external data (e.g. database fields, GET/POST parameters) in a query.

Available sub-properties:

<markername>.value: (value)

Sets the value directly.

<markername>.commaSeparatedList: (boolean)

If set, the value is interpreted as a comma-separated list of values. Each value in the list is individually escaped and quoted.

(stdWrap properties ...)

All stdWrap properties can be used for each markername.

Example:

page.60 = CONTENT
page.60 {
  table = tt_content
  select {
    pidInList = 73
    where = header != ###whatever###
    orderBy = ###sortfield###
    markers {
      whatever.data = GP:first
      sortfield.value = sor
      sortfield.wrap = |ting
    }
  }
}

This example selects all records from table tt_content, which are on page 73 and which don't have the header set to the value provided by the Get/Post variable "first", ordered by the content of the column "sorting".

[tsref:->select]