GROUP BY, DISTINCT, COUNT..... WHICH IS IT???
Posted: Mon Dec 15, 2008 8:43 am
Hi all
I need a genius out there somewhere to find me the solution for something that sounds so very easy.
I have a log of searched entries as an SQL database table. It has just two fields: id, department.
I was to produce a page that shows each individual department searched on (not duplicated - ie. GROUP BY and DISTINCT), with the number next to it showing how many entries of it there are.
ie. there are 25 entries of "commercial", so the result would render as:
Department hits
commercial 25
I have tried the following:
But I get this as a result:
Thank you.
Simon
I need a genius out there somewhere to find me the solution for something that sounds so very easy.
I have a log of searched entries as an SQL database table. It has just two fields: id, department.
I was to produce a page that shows each individual department searched on (not duplicated - ie. GROUP BY and DISTINCT), with the number next to it showing how many entries of it there are.
ie. there are 25 entries of "commercial", so the result would render as:
Department hits
commercial 25
I have tried the following:
Code: Select all
$query = mysql_query ("SELECT DISTINCT department, COUNT(DISTINCT department) as num_off FROM departmentlog GROUP BY department") or die (mysql_error());
while($row = mysql_fetch_array($result)){
echo "$row->department There are " .$row['num_of'] ."finished.";
}Can anyone please help.Warning: mysql_fetch_array(): 3 is not a valid MySQL result resource in other/deptlog.php on line 33
Thank you.
Simon