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());

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

PHP Array quick help
I need

$_SESSION{'username'} to be like this:


if $_SESSION['username'] = "gay

Simple program to copy files between two computers over the web
I use logmein free and often need to move files between my two computers. Generally, I move the file

Firewall / visited websites logger
Hi. I have a firewall implementation and I want to log all the websites visited on the machine. S

ereg_replace()
Basically what i need to do is

$title = "This Suck's"

$striped = ereg_repl

very easy question about SQL info
Hello,
I think that I have a very easy question.
I know how to create a form using php SQL and

New to mysqli library - Multiple query problem
Greetings,

I am writing a batch program that executes 3 queries on a single page. Using mysql

Question about ShowWindow()
Hello....

I'm struggling with sumpin, and I hope y'all can help.

I've got a CFormView

DBCA Templates
Hi all,

I'm working on creating a template for DBCA, but can't find any documentation on the

a very simple php header question (sorry!)
Firstly...I do apologise if this annoys anyone....a header error

I'm do not know php &

Header redirect
Hello ive got a problem ive got form with its action set to itself.
Code: <form id="f

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