seany123 Posted February 25, 2010 Share Posted February 25, 2010 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? Quote Link to comment Share on other sites More sharing options...
ialsoagree Posted February 25, 2010 Share Posted February 25, 2010 We're definitely going to need more information. But here's a tip, in case you aren't aware. all $_POST data is of the string data type, that might play a role depending on what you're trying to add. Quote Link to comment Share on other sites More sharing options...
seany123 Posted February 25, 2010 Author Share Posted February 25, 2010 what more information is needed? Quote Link to comment Share on other sites More sharing options...
ialsoagree Posted February 25, 2010 Share Posted February 25, 2010 Specifically... Where does $_POST['quantity'] come from, what happens between your first posted line and your second posted line. Where are these echoes you refer to taking place? Quote Link to comment Share on other sites More sharing options...
seany123 Posted February 25, 2010 Author Share Posted February 25, 2010 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. Quote Link to comment Share on other sites More sharing options...
shlumph Posted February 25, 2010 Share Posted February 25, 2010 Try casting both vars into an (int) Quote Link to comment Share on other sites More sharing options...
seany123 Posted February 25, 2010 Author Share Posted February 25, 2010 Try casting both vars into an (int) in which way do you mean? Quote Link to comment Share on other sites More sharing options...
shlumph Posted February 27, 2010 Share Posted February 27, 2010 $usrcount = (int)$rcount + (int)$_POST['quantity']; Quote Link to comment Share on other sites More sharing options...
trq Posted February 27, 2010 Share Posted February 27, 2010 What database object is $db? What does $db->execute actually return? Quote Link to comment Share on other sites More sharing options...
seany123 Posted February 27, 2010 Author Share Posted February 27, 2010 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. Quote Link to comment Share on other sites More sharing options...
seany123 Posted February 27, 2010 Author Share Posted February 27, 2010 any other ideas? Quote Link to comment Share on other sites More sharing options...
ialsoagree Posted February 27, 2010 Share Posted February 27, 2010 and yes it does return. The question wasn't "does it return?" it was "what does it return?" Quote Link to comment Share on other sites More sharing options...
seany123 Posted February 27, 2010 Author Share Posted February 27, 2010 well if i echo: $db->execute then it doesnt return anything. Quote Link to comment Share on other sites More sharing options...
jl5501 Posted February 27, 2010 Share Posted February 27, 2010 you have $rcount = $db->execute(.....); immediately after that, put print_r($rcount), and you will see what it returns Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.