Jump to content

Sum database values at once.


jkkenzie

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

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.