| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) | ||||
| Soon to be RICHdoggie! Join Date: Jan 2005 Location: UK
Posts: 2,408
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | mysql: please take a look, too long to explain here Hi, I want to look into a mysql database and get the top 50 most regularly occuring fields. - the field I am looking in is called user_id - I want to get a list of the top 50 most frequently occuring user_ids in this table, with the amount of times they occur. For instance: lets say my table is like this:
"123456" and "2" (most occuring, and number of times occuring) How would I do this? Thanks a lot Tom | ||||
| |
| | #2 (permalink) |
| New Member Join Date: Jan 2006 Location: San Jose, CA
Posts: 19
![]() | Do you know the range of number you are dealing with? 1-100, 1-8000 or anything? I don't know any mySQL parameters to use in this case, but if you know your range, you can probably do a loop and find out. |
| |
| | #3 (permalink) |
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,074
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | have a look at group by and count() on mysql.org they are what you are looking for. http://dev.mysql.com/doc/refman/4.1/...functions.html |
| |
| | #4 (permalink) |
| Domains my Dominion Join Date: Aug 2005 Location: Web 1.0
Posts: 9,963
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | You need something like this: PHP Code:
__________________ NameNewsletter.com - free lists of available domain names ZoneFiles.net (beta) - ccTLD and gTLD droplists |
| |
| | #6 (permalink) |
| Domains my Dominion Join Date: Aug 2005 Location: Web 1.0
Posts: 9,963
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Well I guess you want to display the results of your query right ? So you already have an array (using mysql_fetch_array) For instance consider this code: PHP Code: Please note that the count of USER_ID in your table is aliased as count_USER_ID in my example. You could rename this to something else. Then use the same field name when outputting the results of your query.
__________________ NameNewsletter.com - free lists of available domain names ZoneFiles.net (beta) - ccTLD and gTLD droplists |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| HOWTO: Install the Apache Web Server, Perl, PHP, and MySQL on Windows | deadserious | Webmaster Tutorials | 96 | 05-27-2007 01:24 PM |
| Tutorial: How to Install Apache2 MySQL and PHP on Windows | deadserious | Webmaster Tutorials | 35 | 09-21-2005 09:46 PM |
| 800MB Space, 25GB Bandwidth, Unl. MySQL DB, and more Just $4.00 a month! | resellerlogic | Web Hosting Offers | 0 | 04-05-2005 06:44 PM |
| Tutorial: Getting Started With MySQL (The Basics) | deadserious | Webmaster Tutorials | 3 | 04-18-2004 01:17 PM |
| importing data in MYsql | shakim | Programming | 6 | 08-01-2003 03:46 PM |