|
| Register now to interact with over 11,000 members! Registered users have Posting Privileges, free access to Private Messaging, Email Notifications and more. |
|
|||||||
![]() |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
Join Date: Feb 2002
Posts: 352
Reputation: 27
|
PHP Mysql Query Question
Can someone help me with a PHP mysql query?
I have a database which basically has fields such as transaction_id and product name I would like to show on a certain page "Best Sellers", so I need a sql query (in PHP) to produce this. It would have to separate the product names, then add up the total of each so best sellers would be shown. Example Database: ------------------- trans_id Product Name 1 Widgets 2 Things 3 Widgets 4 Otherthings ----------------------- and now on a page show: BEST SELLERS Widgets 2 Things 1 Other Things 1 Any help would be appreciated. Thanks |
|
|
|
|
#2 |
|
Join Date: Sep 2002
Location: Evansville Indiana
Posts: 220
Reputation: 25
|
are you adding up the number associated with the best sellers? If so where are you getting this number? Is it another field in the table or are you adding it in manually?
i need more information to be able to help you.
__________________
|
|
|
|
|
#3 |
|
Join Date: Feb 2002
Posts: 352
Reputation: 27
|
Thanks for responding. I don't know the answer, that's what I'm trying to find out the best way to do this.
I am wondering is there is a command that can count how many entries in the product field there are, so if "widgets" came up 12 times, then that would be used to compare the other products to see which are the best sellers. |
|
|
|
|
#4 |
|
Older not wiser
Join Date: Nov 2003
Location: Calgary, AB
Posts: 2,473
Reputation: 205
|
You can do it in one query:
PHP Code:
and if you want the Top <n> bestsellers just add the LIMIT clause to the end PHP Code:
Last edited by mitchind : 1-6-05 at 05:27 PM. Reason: Add code for Top # of entries |
|
|
|
|
#5 | |
|
Join Date: Feb 2002
Posts: 352
Reputation: 27
|
Quote:
Thanks a lot, the query works perfectly in phpmyadmin. Can you tell me how you would place the output on a web page? The code came out to: $sql = 'SELECT count(`title`) AS popularity, `title`' . ' FROM `stats` ' . ' GROUP BY title' . ' ORDER BY popularity DESC ' . ' LIMIT 20'; but I don't know how to show the results. Sorry for my lack of knowledge, but I do appreciate any help. |
|
|
|
|
|
#6 |
|
Join Date: Feb 2002
Posts: 352
Reputation: 27
|
Never mind, I figured it out, thanks again.
|
|
|
![]() |
| Thread Tools | Search this Thread |
|
|