Jump to content

sort mysql output


tom_b

Recommended Posts

Hi!

 

I have a table which looks like this:

 

Name1        Name2        Name 3    ID

data            data            data        1

data            data            data        2

data            data            data        3

 

I can output the names, the last entry in each row and the totals from each row with no problem, but I can't sort the rows based on those totals, I'd appreciate any help or ideas!!!

 

Thanks, Tom

 

Link to comment
Share on other sites

Well, I've tried a few different things, this is what I started with.  This first query gives me the last entry into the database:

 

$query = 'SELECT ed, ted, tom FROM week ORDER BY id DESC LIMIT 1';

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

 

$values['ed']['current'] = mysql_result($result, 0, "ed");

$values['ted']['current'] = mysql_result($result, 0, "ted");

$values['tom']['current'] = mysql_result($result, 0, "tom");

 

these next ones give me the totals and the row names:

 

$query = 'SELECT SUM(ed) AS ed, SUM(ted) AS ted, SUM(tom) AS tom FROM week ';

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

 

$values['ed']['sum']  = mysql_result($result, 0, "ed");

$values['ted']['sum'] = mysql_result($result, 0, "ted");

$values['tom']['sum'] = mysql_result($result, 0, "tom");

 

$values['ed']['name'] = mysql_field_name($result, 0);

$values['ted']['name'] = mysql_field_name($result, 1);

$values['tom']['name'] = mysql_field_name($result, 2);

 

this is what I use to get the output

 

foreach ($values as $key => $row) {

  $name[$key] = $row['name'];

  $current[$key]  = $row['current'];

  $sum[$key] = $row['sum'];

 

this all works fine, I just can't sort the rows based on the sums.  Thanks for taking the time to look at it!!

 

Tom

 

P.S.  What is a missing column alias???

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.