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:

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

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:

$select = array(
	'id_mot', 'id_groupe', 'titre', 'descriptif', 
	sql_multi ("titre", $GLOBALS['spip_lang']));
if ($results = sql_select($select, 'spip_mots', "id_groupe=$id_groupe", '', 'multi')) {
	while ($r = sql_fetch($results)) {
		// $r['titre'] $r['multi']
	}
}

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

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

Author Mark Baber Published : Updated : 12/03/23

Translations : English, français