msaz87 Posted February 25, 2010 Share Posted February 25, 2010 Hey all, I'm not sure if the subject is the best way to summarize my problem, but here's what I'm going for: I have a DB table with a bunch of stats for things like TDs, INTs, EXPs, etc. These are used for a formula to devise points, something like (TDs * 6) - (INTs * 4) + (EXPs * 2). But what I'd like to do is query the points leader and I'm not sure how to approach that. Since there is no Points column, I can't do a MAX query, and so I don't know if it's possible to do a formula within the query itself, or what other ideas there might be? Any help is appreciated -- thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/193318-using-an-equation-within-a-query/ Share on other sites More sharing options...
trq Posted February 25, 2010 Share Posted February 25, 2010 Queries can contain expressions, we need an example of what yuor after though. Quote Link to comment https://forums.phpfreaks.com/topic/193318-using-an-equation-within-a-query/#findComment-1017962 Share on other sites More sharing options...
msaz87 Posted February 25, 2010 Author Share Posted February 25, 2010 Queries can contain expressions, we need an example of what yuor after though. So each row in the table is an individual player, with columns for TD, INT, EXP and a few others. I'm producing a "stats" page to display all these with the following query: $stats_query = " SELECT SUM(td_pass), SUM(int_pass), SUM(td), SUM(sacks), SUM(int_d), SUM(`int`) AS exp FROM xxx WHERE player_id = '$player_id'"; Then I also display a "MVP Points" category using the above results: if($week == "-1") { $start_mvp = 20; } else { $start_mvp = 0; } $tdpass_mvp = 4; $intpass_mvp = 3; $td_mvp = 6; $exp_mvp = 2; $sacks_mvp = 2; $intd_mvp = 3; <?php $mvp_points = $start_mvp + ($tdpass_mvp * $row['SUM(td_pass)']) - ($intpass_mvp * $row['SUM(int_pass)']) + ($td_mvp * $row['SUM(td)']) + ($exp_mvp * $row['exp']) + ($sacks_mvp * $row['SUM(sacks)']) + ($intd_mvp * $row['SUM(int_d)']); echo $mvp_points; ?> So what I'm shooting to do is find a way to query which player has the most MVP Points, but the challenge is that there's no MVP Points column -- so I don't really know how to write a sub query or expression or whatever to do that.... Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/193318-using-an-equation-within-a-query/#findComment-1018243 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.