reorder sql query


Posted on 16th Feb 2014 07:03 pm by admin

ok so i have this very simple code:
Code: $query = "SELECT search_keywords, COUNT(search_keywords) AS counter FROM phpbb_popsearch GROUP BY search_keywords ORDER BY counter DESC limit 5";
$res = mysql_query($query) or die(mysql_error());

Did you know?Explore Trending and Topic pages for more stories like this.
while($row = mysql_fetch_array($res)) {
$term = $row["search_keywords"];
echo $term;
}

phpbb_popsearch is a table where i put the last search terms used in my forum search engine

this code will group together the same terms and list the 5 most popular terms

my problem is that the results will be ordered by "counter" which is the number of time a term has been found.

I want to get the 5 most popular results AND THEN, AFTER, list the results alphabetically

if i sort the results alphabetically right in the sql query (replacing "ORDER BY counter" by "ORDER BY search_keywords") it will not work correctly because it will not get the 5 most popular terms but just the 5 first terms, alphabetically sorting them and ignoring the number of times the term has been found

thanks for help
No comments posted yet

Your Answer:

Login to answer
135 Like 10 Dislike
Previous forums Next forums
Other forums

Find occurences of unicode characters in string
I need to prohibit filenames with everything but English characters and numbers but regexp and strin

2 things: enter doesn't work in IE & empty form
i have this search form that works well except for 2 things.

1) on IE when i hit enter instea

Links not updating
I'm trying to fuel a simple navigation system for a news section. It works fine when it comes to ret

ECC6 - Single sign-on
We are in the process of upgrading to ECC 6 which will support single sign on with user passwords al

I am stumped
OK. Here is what I am trying to do. I have the conditions set, and if the conditions are met, I want

Object Interfaces
EDIT: Never mind, I just updated to php 5.

Hey all,

I'm currently experimenting with p

selection tool on raster image
Hi!
I have to implement in my app a selection tool which lets users to select region of any shape

Get Total From While Loop
I'm trying to get the total for each product and add them for a Grand Total to list outside the loop

Mysterious Timeouts
I've deployed a few simple AJAX-enabled web page to a local server that is accessed through the Inte

Issue Parsing XML into table
Hello all,

Im a bit new to php and new to phpfreaks. But thanks in advance for the help!
<

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash