Jiraiya Posted December 9, 2008 Share Posted December 9, 2008 ok my script is supposed to add two variables up and then display them after grouping them. the script half works in the sense that it only totals and groups one variable or the other variable not both im not sure whats wrong $query = "SELECT village, SUM(skill) FROM users GROUP BY village"; $query = "SELECT village, SUM(health) FROM users GROUP BY village"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "Village ". $row['village']. " total power: ". $row['SUM(skill)']; echo "Village ". $row['village']. " total health: ". $row['SUM(health)']; echo "<br />"; } Link to comment https://forums.phpfreaks.com/topic/136243-solved-quick-php-fix/ Share on other sites More sharing options...
wildteen88 Posted December 9, 2008 Share Posted December 9, 2008 Here: $query = "SELECT village, SUM(skill) FROM users GROUP BY village"; $query = "SELECT village, SUM(health) FROM users GROUP BY village"; $result = mysql_query($query) or die(mysql_error()); Only your last query will be run. Your query should be $query = "SELECT village, SUM(skill), SUM(health) FROM users GROUP BY village"; $result = mysql_query($query) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/136243-solved-quick-php-fix/#findComment-710698 Share on other sites More sharing options...
Jiraiya Posted December 9, 2008 Author Share Posted December 9, 2008 what would that fix if it only displayed one result? Link to comment https://forums.phpfreaks.com/topic/136243-solved-quick-php-fix/#findComment-710702 Share on other sites More sharing options...
wildteen88 Posted December 9, 2008 Share Posted December 9, 2008 what would that fix if it only displayed one result? I have only merged your two queries together. As before only the last query was being run: $query = "SELECT village, SUM(health) FROM users GROUP BY village"; The first query: $query = "SELECT village, SUM(skill) FROM users GROUP BY village"; Is not being run at all, as the last query above is overriding it. This is why I have merged your two queries. Link to comment https://forums.phpfreaks.com/topic/136243-solved-quick-php-fix/#findComment-710706 Share on other sites More sharing options...
Jiraiya Posted December 9, 2008 Author Share Posted December 9, 2008 oh ok thanks Link to comment https://forums.phpfreaks.com/topic/136243-solved-quick-php-fix/#findComment-710713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.