Jump to content

[SOLVED] DESC help


mak_gillett

Recommended Posts

I have a program which enters individual football game stats into a mysql database then when I recall I want to have the stats averaged and sorted decsending.

 

So each row in the database has the following data:

 

Id, Tag, PassingStats

 

When I get the data I use: Select tag, AVG(PassingStats) FROM mystats GROUP BY tag ORDER BY passingstats DESC;

 

What is happening however is if one Tag has more entries than another it will not be ordered properly.

 

So Basically the database looks like:

 

--------------------------

| ID | Tag | PassingStats |

--------------------------

| 1 | Mike | 100              |

| 2 | Mike | 150              |

| 3 | John | 200              |

--------------------------

 

When it is displayed after averaging it will be:

 

----------------------

| Tag | PassingStats |

----------------------

| Mike | 125            |

| John | 200            |

----------------------

 

Even though it is supposed to be in decsending order.

 

Now then, if there are the same amount of records for each Tag it will display correctly:

 

----------------------

| Tag | PassingStats |

----------------------

| Mike | 100            |

| Mike | 150            |

| John | 200          |

| John | 250          |

---------------------

 

Will display as:

 

---------------------

| Tag | PassingStats|

---------------------

| John | 225          |

| Mike | 125          |

---------------------

 

Any help would greatly appreciated.

 

 

Link to comment
Share on other sites

try this

Select tag, AVG(PassingStats) FROM mystats GROUP BY tag ORDER BY NULL,passingstats DESC;

 

That didn't seem to work.  Here is the actual code:

 

<?php

$color1 = "#FFFFFF";

$color2 = "#999999";

$row_count = "0";

$query = "SELECT EATag, AVG(PassFor) FROM mystats GROUP BY EATag ORDER BY NULL,PassFor DESC LIMIT 0, 5"; $result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result))

{

$row_color = ($row_count % 2) ? $color1 : $color2;

?>

<tr>

<td width="280" bgcolor="<?php echo $row_color; ?>"><?php  echo $row['EATag']; ?></td>

<td width="110" bgcolor="<?php echo $row_color; ?>"><?php  echo number_format($row['AVG(YardsFor)'], 1); ?></td>

<?php

$row_count++; }

?>

 

 

 

Link to comment
Share on other sites

sorry yaar,

 

first try this

 

Select tag, AVG(PassingStats) as average FROM mystats GROUP BY tag ORDER BY average DESC

 

if it doesn't work , try this

 

Select tag, AVG(PassingStats) as average FROM mystats GROUP BY tag ORDER BY NULL,average DESC

Link to comment
Share on other sites

sorry yaar,

 

first try this

 

Select tag, AVG(PassingStats) as average FROM mystats GROUP BY tag ORDER BY average DESC

 

if it doesn't work , try this

 

Select tag, AVG(PassingStats) as average FROM mystats GROUP BY tag ORDER BY NULL,average DESC

 

Didn't think about that, I'll try when I get home.

Link to comment
Share on other sites

sorry yaar,

 

first try this

 

Select tag, AVG(PassingStats) as average FROM mystats GROUP BY tag ORDER BY average DESC

 

if it doesn't work , try this

 

Select tag, AVG(PassingStats) as average FROM mystats GROUP BY tag ORDER BY NULL,average DESC

 

Well that didn't fix it either.  Instead of averageing the numbers it is displaying everything as 0.0

 

 

Link to comment
Share on other sites

Nevermind I figured it out was I wasn't doing after changing it to your code.

 

I thank you for the help and it is working.  For further use here is what I changed it to:

 

<?php

$color1 = "#999999";

$color2 = "#333333";

$row_count = "0";

 

$query = "SELECT EATag, AVG(RushFor) as average FROM mystats GROUP BY EATag ORDER BY average DESC LIMIT 0, 5";

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result))

{

$row_color = ($row_count % 2) ? $color1 : $color2;

?>

<tr>

<td width="280" bgcolor="<?php echo $row_color; ?>"><font size="2" color="#FFFFFF" face="Courier New, Courier, monospace"><?php  echo $row['EATag']; ?></font></td>

<td width="110" bgcolor="<?php echo $row_color; ?>"><font size="2" color="#FFFFFF" face="Courier New, Courier, monospace"><?php  echo number_format($row['average'], 1); ?></font></td>

<?php

$row_count++;

}

?>

 

 

Link to comment
Share on other sites

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.