The
sql_getfetsel()
function retrieves the single column requested from the first row of the selection. It accepts the same parameters as the
sql_select()
function and is a short-cut for the combination of calling
sql_fetsel()
and
array_shift()
.
Its parameters are:
-#
$select
nominating the desired column,
-#
$from
,
-#
$where
,
-#
$groupby
,
-#
$orderby
,
-#
$limit
,
-#
$having
,
-#
$serveur
,
-#
$option
.
It is used as shown below:
$colonne = sql_getfetsel('colonne', 'table', 'id_table=' . intval($id_table));
Note that an alias can also be defined as shown here:
$alias = sql_getfetsel('colonne AS alias', 'table', 'id_table=' . intval($id_table));
Example
Find out the sector for a section (rubrique):
$id_secteur = sql_getfetsel("id_secteur", "spip_rubriques", "id_rubrique=" . intval($id_rubrique));
The "Job Queue" plugin manages a list of scheduled tasks, so we can find out the date of the next task to be performed with this code:
$date = sql_getfetsel('date', 'spip_jobs', '', '', 'date', '0,1');