Coding with SPIP 2.1
SPIP 2.1 Technical Documentation

> > > > sql_in

sql_in

The sql_in() function is used to create a column condition using the IN SQL keyword.

It employs 5 parameters:

  1. $val is the name of the column,
  2. $valeurs is the list of values, in the form of an array or a comma-separated sequence of strings. These values will be automatically filtered using sql_quote,
  3. $not is used to provide negation. By default it is empty ''; assign 'NOT' to execute a NOT IN condition,
  4. $serveur,
  5. $option.

It can be used as follows:

  1. $vals = array(2, 5, 8);
  2. // where $vals = "2, 5, 8";
  3. $in = sql_in('id_table', $vals);
  4. if ($res = sql_select('column', 'table', $in)) {
  5. // ...
  6. }

Download

Example

The "Tickets" plugin uses sql_in() to obtain the title of a ticket only if it has a status matching one of those listed:

  1. function inc_ticket_forum_extraire_titre_dist($id_ticket){
  2. $titre = sql_getfetsel('titre', 'spip_tickets', array(
  3. 'id_ticket = ' . sql_quote($id_ticket),
  4. sql_in('statut', array('ouvert', 'resolu', 'ferme'))
  5. ));
  6. return $titre;
  7. }

Download

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