Jump to content

Recommended Posts

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

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

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

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.