Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Is it possible to create a view that limits each grouping by 20?
Old 04-12-2010, 10:53 AM Is it possible to create a view that limits each grouping by 20?
Extreme Talker

Posts: 177
Trades: 0
I'm making a golf website for fun, nothing I'm trying to commercialize, and am working on handicap calculations. I have the calculations for 5-19 games done fine. But when you get to 20+ games, it's getting a little trickier. I currently have two views,

"fullGames", which records every users score on a specific tee color for each course. This is only for games that have 18 holes recorded (required for handicap calculations) The fields are as follows:
Code:
score - (score for the round)
cid - (course id of the course played)
ttid - (teetime id...identifier for the game played)
gid - (golfers unique identifier for the user)
teecolor - (tee color played on)
date - (date played)
"gamesPerCourse" -- This view aggregates the fullGames based on course and tee color. The fields are as follows:
Code:
gamesPlayed (total games played for each course and teecolor)
cid (course played at)
teecolor (teecolor played at)
gid (users unique identifier)
So what happens when the site checks to see if it can calculate a handicap is does this:

1. Checks "gamesPerCourse" for entries that have "gamesPlayed" >= 5.
2. If this is the case, it then pulls the appropriate games from the "fullGames" view to calculate the handicap.
If this isn't the case, then the person hasn't played at least 5 games and a handicap can't be computed.

Now when we get to 20+ games, you only use the most recent 20 games to do the calculations. And from the most recent 20 games, you use the lowest 10 scores.

I would rather not just query the 20 most recent games from the "fullGames" view, then iterate through the 20 entries and find the 10 lowest scores.

I've tried to create a query that would keep the 20 most recent games for each user (a modification of the "fullGames" view). This query would then be used as a view and would most likely update the "fullGames" view, but when I use the limit modifier it just limits the result to that number and doesn't limit the results per gid, even though it's grouped by gid.

Am I stuck iterating through 20 rows and doing the calculations of 10 lowest scores in PHP?

Thanks for any help, any questions please ask.

~kb
kbfirebreather is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-12-2010, 01:44 PM Re: Is it possible to create a view that limits each grouping by 20?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
use nested queries (sub queries)

http://dev.mysql.com/doc/refman/5.0/en/subqueries.html
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Is it possible to create a view that limits each grouping by 20?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.60366 seconds with 12 queries