Coding with SPIP 3.0
SPIP3.0 Technical Documentation

> > > > sql_multi

sql_multi

The sql_multi() function applies an SQL expression to a column that contains a multi-lingual expression (<multi>) in order to extract from it the portion corresponding to a nominated language. It returns a character string typed as: expression AS multi. This operation is essentially used to simultaneously request a sort on this column.

It accepts 4 parameters:

  1. $sel is the name of the column,
  2. $lang is the language code (’fr’, ’es’, ...),
  3. $serveur,
  4. $option

It is used as shown below:

  1. $multi = sql_multi('column', 'language');
  2. $select = sql_select($multi, 'table');

Download

Note that in a template file, the loop criteria {par multi xx} where xx is the name of the column to be sorted, will also call this function in order to sort according to the current language.

Example

SPIP uses this function to sort the lists according to the title of an element and according to the site visitor nominated language:

  1. $select = array(
  2. 'id_mot', 'id_groupe', 'titre', 'descriptif',
  3. sql_multi ("titre", $GLOBALS['spip_lang']));
  4. if ($results = sql_select($select, 'spip_mots', "id_groupe=$id_groupe", '', 'multi')) {
  5. while ($r = sql_fetch($results)) {
  6. // $r['titre'] $r['multi']
  7. }
  8. }

Download

In similar fashion, the "Grappes" plugin uses it here:

  1. $grappes = sql_allfetsel("*, ".sql_multi ("titre", "$spip_lang"), "spip_grappes", "", "", "multi");
  2. foreach ($grappes as $g) {
  3. // $g['multi']
  4. }

Download

  • Author :
  • Published :
  • Updated : 02/06/10
  • Translations : English, français