Coding with SPIP 3.0
SPIP3.0 Technical Documentation

> > > > sql_count

sql_count

The sql_count() function returns the number of rows for a selection resource opened with sql_select().

It accepts 3 parameters:

  1. $res is the resource identifier for a selection,
  2. $serveur,
  3. $option.

It is used as shown below:

  1. $res = sql_select('column', 'table');
  2. if ($res and sql_count($res)>2) {
  3. // checks to see if there are at least 3 rows in the results!
  4. }

Download

Example

Possible application: display a count of the total number of elements.

  1. if ($res = sql_select('titre', 'spip_rubriques', 'id_parent=0')) {
  2. $n = sql_count($res);
  3. $i = 0;
  4. while ($r = sql_fetch($res)) {
  5. echo "Section " . ++$i . " / $n : $r[titre]<br />";
  6. // e.g. Section 3 / 12 : La fleur au vent
  7. }
  8. }

Download

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