sql_countsel

The sql_countsel() functions returns the number of rows for a desired selection. It is more-or-less a short way of writing sql_select('COUNT(*)', ...).

It accepts the same arguments as sql_select() except for the first (normally the columns):

  1. $from,
  2. $where,
  3. $groupby,
  4. $having,
  5. $serveur,
  6. $option.

It is used as shown in this example:

  1. $nomber = sql_countsel("table");

Example

Count the number of keywords in a given keyword group:

  1. $groupe = sql_countsel("spip_mots", "id_groupe=$id_groupe");

Return false if a section has any articles NOT in the trash:

  1. if (sql_countsel('spip_articles', array(
  2. "id_rubrique=$id_rubrique",
  3. "statut <> 'poubelle'"
  4. ))) {
  5. return false;
  6. }

Download

If the spip_notations_objets table in the "Notations" table does not yet have any entry for the object identifier specified, then perform a database insert, otherwise perform an update:

  1. // Update or insert?
  2. if (!sql_countsel("spip_notations_objets", array(
  3. "objet=" . sql_quote($objet),
  4. "id_objet=" . sql_quote($id_objet),
  5. ))) {
  6. // Insert a record for the object notation
  7. sql_insertq("spip_notations_objets", ...);
  8. // ...
  9. } else {
  10. // Update if there already is a record
  11. sql_updateq("spip_notations_objets", ...);
  12. // ...
  13. }

Download

Author Mark Baber Published : Updated : 15/02/12

Translations : English, français