How do I use GROUP BY
to display the result by group (email)?
this is my file .php
<?php
/**
* Created by PhpStorm.
*/
namespace Drupal\gestion_contact\Controller;
use Drupal\Core\Controller\ControllerBase;
class GestionContactController extends ControllerBase
{
public function admin() {
$result = db_query("SELECT * FROM {contact}");
$node = $result->fetchAll();
return array(
'#theme' => 'gestion_contact',
'#nodes'=> $node,
);
}
public function delete($id)
{
db_delete('contact')
->condition('id_contact', $id)
->execute();
drupal_set_message(t('Your form has been deleted'));
$result = db_query("SELECT * FROM {contact}");
$node = $result->fetchAll();
return array(
'#theme' => 'gestion_contact',
'#nodes' => $node,
);
}
public function afficher()
{
$result = db_query("SELECT * FROM {contact} WHERE vu = :vu",
array(':vu' => 'false'));
$node = $result->fetchAll();
return array(
'#theme' => 'nouveaux_contact',
'#nodes' => $node,
);
}
}
...BY: SELECT * FROM...
, this is causing error. Look at Edit 1 on my answer, by default Drupal use sql_mode with 'only_full_group_by', this means that you cannot use a aggregate function (GROUP BY) with non aggregated column. In this Edit also provide an example to solve this.SELECT email
instead ofSELECT *
, if you only need email column.