SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: How sort on "count."
-
Mar 31, 2005, 06:16 #1
- Join Date
- Jul 2000
- Location
- Western Massachusetts, USA
- Posts
- 1,389
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How sort on "count."
I have built a report on a query that "counts" the number of search phrases, and displays them grouped by search phrase with the number of instances of each phrase. Works fine at:
http://www.kripalu.org/search_report_v2.php
if you plug in date range of 3/29 - 3/30/05
Now I have created a version to sort by "count."
However, as "count" is not a real field, the script produces an error.
http://www.kripalu.org/search_report_v3.php
Again, to test plug in date range of 3/29 - 3/30/05
Error retrieving search data from database!
Error: Unknown column 'count' in 'order clause'PHP Code:$sql = "select search_phrase, COUNT(*) AS num_search_phrase,
found,
found_date
from
search
where
found_date >= $startdate and found_date <= $enddate
group by search_phrase
order by
count desc";
-
Mar 31, 2005, 06:21 #2
Hi,
depending on the DB you may try
ORDER BY COUNT(*) DESC
or
ORDER BY num_search_phrase DESCNever ascribe to malice,
that which can be explained by incompetence.
Your code should not look unmaintainable, just be that way.
-
Mar 31, 2005, 06:51 #3
- Join Date
- Jul 2000
- Location
- Western Massachusetts, USA
- Posts
- 1,389
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks kleineme.
PHP Code:ORDER BY num_search_phrase DESC
Bookmarks