TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-20-2008, 06:51 PM   #1 (permalink)
The Wanderer
 
paulOr's Avatar
 
Join Date: Nov 2007
Location: Edinburgh
Posts: 21
Thanks: 1
paulOr is on a distinguished road
Default 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.
__________________
paulOr.net
paulOr is offline  
Reply With Quote
Old 10-20-2008, 07:35 PM   #2 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

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>'
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 03:01 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design