Jump to content

sort on two query results


tom_b

Recommended Posts

O.K., I hope I explain this clearly.  The following code is 2 separate queries to the same table.  Everything works fine, I can input data and output the data no problem.  What I can't seem to figure out (and I have tried!!!) is how to sort the output based on the "sum" query.  Any ideas at all?

 

Thanks, Tom

 

 

$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");

 

$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);

 

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

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

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

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

 

echo "<font color ='blue' font size = '3'>$name[$key]";?

></td><td width="35"><?php

echo "<font color ='blue' font size = '3'>$current[$key]";

?></td><td><?php

echo "<font color ='blue' font size = '3'>$sum[$key] <br>";

?></td>

 

Link to comment
https://forums.phpfreaks.com/topic/38842-sort-on-two-query-results/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.