Jump to content

Recommended Posts

I have a database with 2 fields (Country and Value).

 

i cant figure out how to sum values for particular country and put them in variables;

 

like COuntry1- sum=45

    country2- sum=50

 

this is my code so far:

//Get the country with the highest rank value
	$getresults4 = mysql_query("SELECT DISTINCT strCountry FROM tblcountries WHERE Par_Id='$parid' AND projectid='$proid' ORDER BY strCountry");
$count4=0;
        while($rows4 = mysql_fetch_array($getresults4))
	{
	$countryname4[]=$rows4['strCountry'];
	$count4++;
	 }
$count41=0;
        while($count41<=$count4)
	{
	$getresults5 = mysql_query("SELECT Par_Value FROM tblcountries WHERE Par_Id='$parid' AND projectid='$proid' AND strCountry='$countryname[$count41]' ORDER BY strCountry");
	    
		while($rows5 = mysql_fetch_array($getresults5))
             {
		 $sum=$sum+$rows5['Par_Value'];			 
		 } 
	$count41++;
	}		 	 

Link to comment
https://forums.phpfreaks.com/topic/105002-sum-database-values-at-once/
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.