Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-11-2012, 02:18 AM   PM User | #1
prizegrand
New Coder

 
Join Date: Dec 2011
Posts: 32
Thanks: 2
Thanked 0 Times in 0 Posts
prizegrand is an unknown quantity at this point
Question Help! -Adding rows and values, then sorting

Hi,

I'm kind of confused what i should do here. Here is my picture of database structure:


So what i want to do is select all the rows and add the cash/points a user accumulated from individual rows, and finally pull all the rows and sort them based on the number of rows per each user, Descending, where the user with the most "entries" or rows in the table are listed first. Any idea on how i can do that?

-prizegrand
prizegrand is offline   Reply With Quote
Old 02-11-2012, 04:56 AM   PM User | #2
totesmagotes
New Coder

 
Join Date: Oct 2010
Posts: 31
Thanks: 2
Thanked 0 Times in 0 Posts
totesmagotes is an unknown quantity at this point
Not 100% what you're asking, but this might help to get you started

Code:
mysql_query("SELECT SUM(cash), SUM(points) FROM table WHERE (Your parameters go here)";
That will return two arrays, one is the sum of the cash one, and the other is the sum of the points accumulated, depending on what you're searching for.

More details would help.
totesmagotes is offline   Reply With Quote
Old 02-11-2012, 04:57 PM   PM User | #3
prizegrand
New Coder

 
Join Date: Dec 2011
Posts: 32
Thanks: 2
Thanked 0 Times in 0 Posts
prizegrand is an unknown quantity at this point
Can it just be so it counts the number of rows each user has and lists them by the most to the least?
So its like this:
User
1
1
1
2
2
66
99
22
Where the user with ID of 1, will be listed first, and 2 second, and 66, 99, 22 listed last.
prizegrand is offline   Reply With Quote
Old 02-11-2012, 05:44 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Add a GROUP BY userid to the query to keep userid => sum values. Alias the values and add an ORDER BY to which you want to order them by.
Fou-Lu is offline   Reply With Quote
Old 02-12-2012, 08:26 PM   PM User | #5
prizegrand
New Coder

 
Join Date: Dec 2011
Posts: 32
Thanks: 2
Thanked 0 Times in 0 Posts
prizegrand is an unknown quantity at this point
Sounds good.
How can i make it numbered in a list, like:
Place | Username | Entries
1 test 97
2 dddddd 85
3 testttt 75
4 fdasf 65
5 dsffsd 55
Where i can list it by place, and have numbers accompany it? Would i use an ordered list <ol> ?
prizegrand is offline   Reply With Quote
Old 02-12-2012, 08:32 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
What does Entries represent?
Fou-Lu is offline   Reply With Quote
Old 02-13-2012, 04:07 AM   PM User | #7
prizegrand
New Coder

 
Join Date: Dec 2011
Posts: 32
Thanks: 2
Thanked 0 Times in 0 Posts
prizegrand is an unknown quantity at this point
Entries represent the number of rows the user has in the table. Generally, 1 entry is one row
prizegrand is offline   Reply With Quote
Old 02-13-2012, 11:33 AM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Then its not a sum, its a count.
Code:
SELECT username, count(*) AS cnt FROM table GROUP BY username ORDER BY cnt DESC
Use your iteration to add the Place, as that appears to be just an incrementing row value.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
entries, prizegrand, rows, sort

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:24 AM.


Advertisement
Log in to turn off these ads.