Jump to content

help with SUM()


seany123

Recommended Posts

all i wanna do is find a way to be able to use the result of this query so i can add and subtract from it.

 

 

$rcount = $db->execute("SELECT SUM(quantity) as '' FROM items WHERE id = '".$_POST['id']."'");

 

when i echo it gives me the correct value...

 

but when i try this:

 

$rcount = ($rcount + $_POST['quantity']);

 

it echo's  the result of ($_POST['quantity'] + 1)

 

can anyone give me help here please?

 

Link to comment
https://forums.phpfreaks.com/topic/193388-help-with-sum/
Share on other sites

This is an exact copy of that part of the script.

 


	if ($_POST['send2']){


	$rcount = $db->execute("SELECT SUM(quantity) as'' FROM items WHERE id = '".$_POST['id']."'");

	echo $rcount;

	$usrcount = ($rcount + $_POST['quantity']);

	echo $usrcount;

	echo $_POST['id'];

	echo $_POST['quantity'];

 

 

The $_POST comes from a form which is on the same page.

 

 

Link to comment
https://forums.phpfreaks.com/topic/193388-help-with-sum/#findComment-1018227
Share on other sites

What database object is $db? What does $db->execute actually return?

 

well im using adodb.

 

$db = &ADONewConnection('mysql'); //Connect to database
$db->Connect($config_server, $config_username, $config_password, $config_database);

 

and yes it does return.

 

$usrcount = (int)$rcount + (int)$_POST['quantity'];

 

no that didnt work. echo'd the same as if the (int) wasn't there.

Link to comment
https://forums.phpfreaks.com/topic/193388-help-with-sum/#findComment-1019017
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.