Coding with SPIP 3.0
SPIP3.0 Technical Documentation

> > > > sql_create_view

sql_create_view

The sql_create_view() function creates a view for the selection query provided. The view can then be used by SPIP loops or by other selection commands.

It accepts 4 parameters:

  1. $nom is the name of the view created,
  2. $select_query is the selection query,
  3. $serveur,
  4. $option.

It can be used in conjunction with the sql_get_select function to retrieve the desired selection:

  1. $selection = sql_get_select('column', 'table');
  2. sql_create_view('myview', $selection);
  3. // utilisation
  4. $result = sql_select('column', 'myview');

Download

Note: Whenever a selection column uses the 'name.column' notation, you absolutely must declare an alias for the column, otherwise certain database ports (SQLite in particular) will not create the expected view, e.g. 'name.column AS column'.

Example

This small example demonstrates this function by creating a (rather useless) table from 2 columns in a section:

  1. $select = sql_get_select(array(
  2. 'r.titre AS t',
  3. 'r.id_rubrique AS id'
  4. ), array(
  5. 'spip_rubriques AS r'
  6. ));
  7. // create the view
  8. sql_create_view('spip_short_rub', $select);
  9. // use it:
  10. $titre = sql_getfetsel('t', 'spip_short_rub', 'id=8');

Download

The view could also be used within a SPIP template file, as in:

  1. <BOUCLE_view(spip_short_rub) {id=8}>
  2. <h3>#T</h3>
  3. </BOUCLE_view>

Download

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