Click here to Skip to main content
15,893,790 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have a mysql database that contains numeric values.

Example :

affID l Amount

MW001 5
MW004 10
MW001 11
MW001 15
MW004 20

What i need is help on a query that will caluculate the Total Amount for the affID MW001.

So for example : MW001 = 31

At the moment it gets the value of the affID through a login session.

this is what i have and it is not working :

$sql = "SELECT affID, COUNT(*) as c FROM taffiliate WHERE AffCommision = '" . $_SESSION['affID'] . "'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
echo $row['c'] ;
Posted
Updated 14-Aug-14 6:03am
v2

I'm not sure of mySQL itself, but ANSI SQL would be:

SELECT SUM(Amount)
FROM taffiliate
WHERE affID = 'MW001'
 
Share this answer
 
try this

PHP
$sql="SELECT  SUM(amount)as sum  FROM `taffiliate` WHERE affid='MW001'";

$result=  mysqli_query($con, $sql) or die(mysqli_error($con));




    while ($row=  mysqli_fetch_array($result))
    {
        $y= $row['sum'].'<br>';


    }




you can use where condition as you want i just gave one example, for MW001, the total will be 31
 
Share this answer
 
try this

PHP
$sql="SELECT  SUM(amount)as sum  FROM `taffiliate` WHERE affid='MW001'";

$result=  mysqli_query($con, $sql) or die(mysqli_error($con));




    while ($row=  mysqli_fetch_array($result))
    {
        $y= $row['sum'].'<br>';


    }




you can use where condition as you want i just gave one example, for MW001, the total will be 31
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900