php - PDO ORDER BY COUNT -
i need pdo query top 20 searched terms (returning search-term , number of times used).
this sql want (tested in phpmyadmin) . . .
select searchterm, count(*) rowcount table grouping searchterm order rowcount desc limit 20
. . . pdo returns rowcount 1.
i 've read loads of related posts, can't seem adapt solutions problem (probably because don't understand pdo enough).
didn't want post pdo code i'm using wrapper i've built (that works great) , think need start scratch problem . . . here (sanitised wrapper) . . .
$query = $this -> db -> prepare ( select searchterm, count(*) rowcount table grouping searchterm order rowcount desc limit 20); $query -> execute (); $return = $query -> fetchall(pdo::fetch_assoc);
could give me output of ? , i'll edit answer. utilize pdo grouping first column:
$query = $this->db->prepare("select `searchterm`, count(*) `rowcount` `table` order rowcount desc limit 20"); $query->execute(); $return = $query->fetchall(pdo::fetch_column|pdo::fetch_group);
just show me var_dump($return)
php pdo
No comments:
Post a Comment