tom_b Posted February 17, 2007 Share Posted February 17, 2007 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 More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 sort($sum); lol oh you want to sort it in the SQL suery using SORT BY sum somewhere near the end Link to comment https://forums.phpfreaks.com/topic/38842-sort-on-two-query-results/#findComment-186777 Share on other sites More sharing options...
tom_b Posted February 17, 2007 Author Share Posted February 17, 2007 I've tried both of these (and other variations) with no luck. $query = 'SELECT SUM(ed) AS ed, SUM(ted) AS ted, SUM(tom) AS tom FROM week sort($sum)'; or $query = 'SELECT SUM(ed) AS ed, SUM(ted) AS ted, SUM(tom) AS tom FROM week sort by sum'; Link to comment https://forums.phpfreaks.com/topic/38842-sort-on-two-query-results/#findComment-186784 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.