| Frank M Flynn 2005-04-18, 8:56 pm |
| There are two places you can figure out the average: in MySQL or in
PHP. Then you want to sort the results by this Average: in MySql use
"ORDER BY" and in php use "array_multisort"
in MySQL your SQL might look like:
SELECT TEAM, PLAYED, WIN, LOSS, DRAW, POINTS, POINTS / PLAYED as
AVERAGE
FROM <your table>
ORDER BY AVERAGE desc
in PHP you'd have to loop through your results loading them into a
local array with an additional column for average and then use
array_multisort which has many options (and I don't exactly remember
how to make it work exactly but look at:
<http://www.phpbuilder.com/manual/fu...y-multisort.php> to
see).
I'd do it in MySQL but that's me...
Good luck,
Frank
On Apr 17, 2005, at 2:13 PM, php-db-digest-help@lists.php.net wrote:
> From: Vikas Nanda <vikasnandauk@yahoo.co.uk>
> Date: April 17, 2005 7:39:57 AM PDT
> To: php-db@lists.php.net
> Subject: php and tables
>
>
> Hi
>
> I am new to php and mysql and am having a few problems that I hope
> someone can help with.
>
> What I am trying to do is to display ratings for particular teams
> using some basic code. I needed to print the information out on a
> table with the highest average at the top and then ascending. I have
> all this info stored in a mysql db.
> eg
> TEAM PLAYED WIN LOSS DRAW POINTS AVERAGE
> ENGLAND 16 6 6 4 16
> 1.00
>
> I don't know how to print variables out in a table and I don't know
> how to make it ascending.
>
> Any help would be much appreciated.
>
> Thanks
>
> Vikas
|