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
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
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
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.