Jump to content

sum of table to get value


DrTrans

Recommended Posts

Property

Amount

 

Test

100

Test

300

Test

500

 

 

I want to be able to add up all fields of  Amount By Property so it gives me a value of ex. 900.

 

my code


$query9 = "SELECT SUM(Amount) FROM gldetail Where Property_ID = '$prop'"; 
		$result9 = mysql_query($query9);
        echo"$result9";
		$sum = mysql_fetch_assoc($result9);
            $sum2 = $sum['Amount'];
$sum3 =  number_format($sum2,2);

 

Thanks for your help.

 

Link to comment
https://forums.phpfreaks.com/topic/198533-sum-of-table-to-get-value/
Share on other sites


$connect = mysql_connect("localhost","root","");
        mysql_select_db("tenantpro");
        $rentid ="6";
$query9 = "SELECT SUM(Amount) as amount FROM gldetail WHERE Property_ID = '$prop'"; 
echo "$query9";
		$result9 = mysql_query($query9);
		echo "$result9";

    	$sum = mysql_fetch_assoc($result9);
             $sum2 = $sum['amount'];

You already have an existing thread for this problem, where someone already suggested echoing the query statement and executing that query directly against your database.

 

For the code you have shown, echoing the $query9 variable cannot give the result you just posted. What is your real code?

 

And the answer to your problem is that either your query is failing due to an error in the query or with the database server or your WHERE clause in the query is matching no rows.

 

database.png

 


$prop = $_GET['prop'];
$connect = mysql_connect("localhost","root","");
        mysql_select_db("tenantpro");
        $rentid ="6";
$query9 = "SELECT SUM(Amount) as amount FROM gldetail WHERE Property_ID = '$prop'"; 
echo $query9; 
		$result9 = mysql_query($query9);


    	$sum = mysql_fetch_assoc($result9);
             $sum2 = $sum['amount'];

 

Responce:

SELECT SUM(Amount) as amount FROM gldetail WHERE Property_ID = '435'

 

 

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.