TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Fetching top amount of keywords (http://www.talkphp.com/general/3503-fetching-top-amount-keywords.html)

paulOr 10-20-2008 06:51 PM

Fetching top amount of keywords
 

Im looking for a way to show the results of this database like this:

Top Keywords
  1. Code
  2. MySQL
  3. poop
  4. ass

Because, if you look at screenshot, Code has 3 entries ( so #1 ) MySQL has two entries ( #2 ) and then the rest under it :)

I have this so far, but it doesnt work :(
Code:

        $q = mysql_query("SELECT COUNT(`id`) AS freq, `name` FROM `table` GROUP BY `name` ORDER BY freq ASC");
       
        echo '<ul>';
        while($fetch = mysql_fetch_array) {
                echo '<li>'.$fetch["name"].'</li>';
        }
        echo '</ul>';

Thanks in advance.

sketchMedia 10-20-2008 07:35 PM

The sql doesnt seem to be the problem, although you may want to change it to DESC in order to get the most frequent first.

There are some errors in you script, you have not passed mysql_fetch_array a valid result link.
PHP Code:

    $q mysql_query("SELECT COUNT(`id`) AS freq, `name` FROM `table` GROUP BY `name` ORDER BY freq DESC");
    
    echo 
'<ul>';
    while(
$fetch mysql_fetch_array($q)) {
        echo 
'<li>'.$fetch["name"].'</li>';
    }
    echo 
'</ul>'



All times are GMT. The time now is 05:55 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0