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

[Need Help] php timing issues
I don't know what is going wrong. I need some help with being able to set an image at 9:00am Colorad

$get problem
Hi Guys ...

can you please tell me what i am doing wrong here
Code: <?php

include problem
I have my root folder as:
Code: $root = $_SERVER["SITE_HTMLROOT"]; // the server root<

Auto-populating dropdowns and multiple forms.
Here's what I have so far:

First drop down = select a state (works)
This populates the sec

rookie looking for help coding a CSS form with PHP
I'm trying to figure out how to add PHP code to my xhtml form so that it is a working form embedded

Help adding strtolower( to my in_array
strtolower i need to add it to this to work, iuno how.

Code: $moderators = array('Admin', 'ba

please help me in this update statment
hi every one

if I have table and this data in it

id name
10

Include ("Absolute Path") of a file?
I'm not sure what I'm doing wrong. I am writing my php code in the same directory of the file that

Sub-domains & calling unique content
Hello,

Is there a way use something similar to the $_GET function for a sub-domain? I to be a

Material Issuing for receiving batch
Dear All experts in MM/ PP,

Material issuing from main stores to factory is currently usi

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