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:

  1. $select nominating the desired column,
  2. $from,
  3. $where,
  4. $groupby,
  5. $orderby,
  6. $limit,
  7. $having,
  8. $serveur,
  9. $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));


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');

Author Mark Baber Published : Updated : 17/05/10

Translations : English, français