Coding with SPIP 2.1
SPIP 2.1 Technical Documentation

> > > > sql_allfetsel

sql_allfetsel

The sql_allfetsel() functions retrieves an array with all of the results of a selection. It accepts the same parameters as the sql_select() function and is a combined short-cut to replace calling sql_select() and sql_fetch_all(). As it stores all of the results in a PHP array, be careful not to exceed the memory limit allowed to PHP if you are dealing with large data volumes.

It accepts 9 parameters:

  1. $select,
  2. $from,
  3. $where,
  4. $groupby,
  5. $orderby,
  6. $limit,
  7. $having,
  8. $serveur,
  9. $option.

The sql_allfetsel() function is used as shown below:

  1. $all = sql_allfetsel('column', 'table');
  2. // $all[0]['column'] is the column in the first line retrieved

Download

Example

Select all of the objet / id_objet pairs associated with a particular document:

  1. if ($liens = sql_allfetsel('objet, id_objet', 'spip_documents_liens', 'id_document=' . intval($id))) {
  2. foreach ($liens as $l) {
  3. // $l['objet'] and $l['id_objet']
  4. }
  5. }

Download

The "Contact avancé" plugin selects all of the emails for the recipients of a message as shown below:

  1. // Retrieve who it was sent to
  2. $destinataire = _request('destinataire');
  3. if (!is_array($destinataire)) {
  4. $destinataire = array($destinataire);
  5. }
  6. $destinataire = array_map('intval', $destinataire);
  7. $mail = sql_allfetsel('email', 'spip_auteurs', sql_in('id_auteur', $destinataire));

Download

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