db_distinct_field

  1. drupal
    1. drupal6
    2. drupal7 database.inc
Versionen
drupal6 – drupal7 db_distinct_field($table, $field, $query)

Adds the DISTINCT flag to the supplied query and returns the altered query.

The supplied query should not contain a DISTINCT flag. This will not, and never did guarantee that you will obtain distinct values of $table.$field.

Übergabeparameter

$table Unused. Kept to retain API compatibility.

$field Unused. Kept to retain API compatibility.

$query Query to which the DISTINCT flag should be applied.

Rückgabewert

SQL query with the DISTINCT flag set.

Verwandte Themen

▾ 1 function calls db_distinct_field()

db_rewrite_sql in includes/database.inc
Rewrites node, taxonomy and comment queries. Use it for listing queries. Do not use FROM table1, table2 syntax, use JOIN instead.

Code

includes/database.inc, line 407

<?php
function db_distinct_field($table, $field, $query) {
  $matches = array();
  if (!preg_match('/^SELECT\s*DISTINCT/i', $query, $matches)) {
    // Only add distinct to the outer SELECT to avoid messing up subqueries.
    $query = preg_replace('/^SELECT/i', 'SELECT DISTINCT', $query);
  }

  return $query;
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen