Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/193318-using-an-equation-within-a-query/
Share on other sites

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.