Hi,
I'm using Mysql and PHP,I have a simple table in my DB, looks something like this:
id jim bob bill
1 20 30 15
2 20 35 15
etc, what i need to do is get the sums for each column (I can do that), then output each field_name with the corresponding sum sorted desc like this
bob 65
jim 40
bill 30
here's the query to get the sums:
<?php
$query = 'SELECT SUM(jim) AS jim, SUM(bob) AS bob, SUM(bill) AS bill FROM week';
$result = mysql_query($qu ery) or die(mysql_error ());
and I use this to get the field names:
$values['jim']['name'] = mysql_field_nam e($result, 0);
$values['bob']['name'] = mysql_field_nam e($result, 1);
$values['bill']['name'] = mysql_field_nam e($result, 2);
?>
I can get the sums, I can get the field names, but I can't get them into separate rows and sort them by the sums. I've tried a number of things but I'm stumped!!! Any ideas, hints?
Thanks, Tom
I'm using Mysql and PHP,I have a simple table in my DB, looks something like this:
id jim bob bill
1 20 30 15
2 20 35 15
etc, what i need to do is get the sums for each column (I can do that), then output each field_name with the corresponding sum sorted desc like this
bob 65
jim 40
bill 30
here's the query to get the sums:
<?php
$query = 'SELECT SUM(jim) AS jim, SUM(bob) AS bob, SUM(bill) AS bill FROM week';
$result = mysql_query($qu ery) or die(mysql_error ());
and I use this to get the field names:
$values['jim']['name'] = mysql_field_nam e($result, 0);
$values['bob']['name'] = mysql_field_nam e($result, 1);
$values['bill']['name'] = mysql_field_nam e($result, 2);
?>
I can get the sums, I can get the field names, but I can't get them into separate rows and sort them by the sums. I've tried a number of things but I'm stumped!!! Any ideas, hints?
Thanks, Tom
Comment