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
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'];

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

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'

 

 

Link to comment
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.