Help - Search - Members - Calendar
Full Version: Help With Sum()
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
homes_kelly
I'm creating something small for reps to follow up on sales.

can somebody help me out with this

Quote:
$com = SUM($amount*0.25);

$qry = "INSERT INTO data (date, rep, client, amount, com, status) VALUES ('$postdate', '$rep', '$client', '$amount', '$com', 'pending')";
$result = mysql_query($qry);
if($result) {
header("location: success.php");
exit();
}else {
die("Query failed");
}
the problem is $com commision on sales.
swordz
I think you should be using array_sum.

swordz
Ed
I'm not convinced this is an actual question, judging by the links within your post and other posts, I'm pretty sure this is an attempt to boost PR for the linked sites...

As to your question, 'SUM()' is a MySQL function to be supplied as a string in the query:

SQL
SELECT SUM(price) AS total FROM products


If you're trying to perform arithmetic in php you can omit the 'SUM(' part;

CODE
$com = $amount*0.25;


Providing $amount is a valid integer that will return the expected result. I suggest reading the manual on basic php before trying to attempt MySQL database connections / queries and the like.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.