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

Material Master Update through BAPI - Follow up material not updated
Hi Experts,

I am updating the material master through a custom transaction using the BAPI

Apart from cron
I need to run a php file every one hour. Is there any other solution apart from cron job?

curl javascript problem
Hi Experts.
I'm new curl and wanna to get some info from this http://www.amadeus.net/

when

RSS feed - FeedList for WordPress
Hi,

I'm trying to alter the FeedList plugin for WordPress so that I can click on the title of

Remove Rows From Database ad
Hi All,

I have this:

Code: [Select]<?php
session_start();
include('../com

date function help
i need help with date function

Code: [Select]<!DOCTYPE HTML PUBLIC "-//W3C//DTD H

Need some ideas as to how to go about sorting this array...
Here's how the array's are created..

Code: <?php
while ($x = readdir($dp)) {

moving mouse to display image coordinates
I have an existing MFC application that shows an image in the main window.
I'd like to be able to

Binding 2 UDP sockets on same port, connected to different destinations, 1 receives
Hello,
My application wants to send/recv data to 2 different UDP ports on a remote computer, us

Calander layout
Hi i know this sounds like a simple question but i cant find the answer to it anywhere i have added

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