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? Link to comment https://forums.phpfreaks.com/topic/193388-help-with-sum/ 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. Link to comment https://forums.phpfreaks.com/topic/193388-help-with-sum/#findComment-1018174 Share on other sites More sharing options...
seany123 Posted February 25, 2010 Author Share Posted February 25, 2010 what more information is needed? Link to comment https://forums.phpfreaks.com/topic/193388-help-with-sum/#findComment-1018189 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? Link to comment https://forums.phpfreaks.com/topic/193388-help-with-sum/#findComment-1018206 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. Link to comment https://forums.phpfreaks.com/topic/193388-help-with-sum/#findComment-1018227 Share on other sites More sharing options...
shlumph Posted February 25, 2010 Share Posted February 25, 2010 Try casting both vars into an (int) Link to comment https://forums.phpfreaks.com/topic/193388-help-with-sum/#findComment-1018242 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? Link to comment https://forums.phpfreaks.com/topic/193388-help-with-sum/#findComment-1018283 Share on other sites More sharing options...
shlumph Posted February 27, 2010 Share Posted February 27, 2010 $usrcount = (int)$rcount + (int)$_POST['quantity']; Link to comment https://forums.phpfreaks.com/topic/193388-help-with-sum/#findComment-1018765 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? Link to comment https://forums.phpfreaks.com/topic/193388-help-with-sum/#findComment-1018767 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. Link to comment https://forums.phpfreaks.com/topic/193388-help-with-sum/#findComment-1019017 Share on other sites More sharing options...
seany123 Posted February 27, 2010 Author Share Posted February 27, 2010 any other ideas? Link to comment https://forums.phpfreaks.com/topic/193388-help-with-sum/#findComment-1019051 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?" Link to comment https://forums.phpfreaks.com/topic/193388-help-with-sum/#findComment-1019085 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. Link to comment https://forums.phpfreaks.com/topic/193388-help-with-sum/#findComment-1019112 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 Link to comment https://forums.phpfreaks.com/topic/193388-help-with-sum/#findComment-1019116 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.