seany123 Posted November 22, 2009 Share Posted November 22, 2009 i have this code: $num = 250; $count = ($num - $rcount); echo $rcount; echo "<br>"; echo $count; when i echo $rcount it gives me 153... so my calculations is 250-153 = 97. but for some reason $count is echoing: 249. anyone know what im doing wrong? Quote Link to comment Share on other sites More sharing options...
Cardale Posted November 22, 2009 Share Posted November 22, 2009 $num = 250; $count = $num - $rcount; echo $rcount; echo "<br />"; echo $count; Quote Link to comment Share on other sites More sharing options...
seany123 Posted November 22, 2009 Author Share Posted November 22, 2009 $num = 250; $count = $num - $rcount; echo $rcount; echo "<br />"; echo $count; that changed nothing. Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted November 22, 2009 Share Posted November 22, 2009 no, that wouldn't change anything. post more of your code. there is obviously something going on that you are not showing here, since this is just simple math. you didn't even post the $rcount variable. Quote Link to comment Share on other sites More sharing options...
seany123 Posted November 22, 2009 Author Share Posted November 22, 2009 $rcount = $db->execute("SELECT SUM(quantity) as'' FROM items WHERE player_id = '$player->id'"); $num = 250; $count = $num - $rcount; echo $rcount; echo "<br>"; echo $count; Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted November 22, 2009 Share Posted November 22, 2009 what does this give you: $rcount = $db->execute("SELECT SUM(quantity) AS `count` FROM `items` WHERE `player_id` = '".$player->id."'"); echo $rcount->count; Quote Link to comment Share on other sites More sharing options...
dbillings Posted November 22, 2009 Share Posted November 22, 2009 try echoing $rcount before you perform the math. echo $rcount; // for testing purposes $num = 250; $count = ($num - $rcount); echo $rcount; echo "<br>"; echo $count; Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted November 22, 2009 Share Posted November 22, 2009 $rcount = $db->execute("SELECT SUM(quantity) as'' FROM items WHERE player_id = '$player->id'"); $rcount is likely to be a resource (a database result) rather than an actual integer value. You need to read your value from the result set. Why as''? Quote Link to comment Share on other sites More sharing options...
seany123 Posted November 23, 2009 Author Share Posted November 23, 2009 $rcount = $db->execute("SELECT SUM(quantity) as'' FROM items WHERE player_id = '$player->id'"); $rcount is likely to be a resource (a database result) rather than an actual integer value. You need to read your value from the result set. Why as''? because if not i get this echo'd "SUM(quantity) 153 " try echoing $rcount before you perform the math. echo $rcount; // for testing purposes $num = 250; $count = ($num - $rcount); echo $rcount; echo "<br>"; echo $count; That just did nothing different. what does this give you: $rcount = $db->execute("SELECT SUM(quantity) AS `count` FROM `items` WHERE `player_id` = '".$player->id."'"); echo $rcount->count; that gave me no echo from $rcount. Quote Link to comment Share on other sites More sharing options...
seany123 Posted November 23, 2009 Author Share Posted November 23, 2009 scratch that. Quote Link to comment Share on other sites More sharing options...
seany123 Posted November 23, 2009 Author Share Posted November 23, 2009 this still isnt working and i havnt been able to find the problem anyone know? Quote Link to comment Share on other sites More sharing options...
seany123 Posted November 26, 2009 Author Share Posted November 26, 2009 Anyone got any ideas? Quote Link to comment Share on other sites More sharing options...
seany123 Posted November 26, 2009 Author Share Posted November 26, 2009 Okay so because nobody has been able to help me with this maybe if i ask i different question i might find more joy.... does anyone know how to add up all the values in a table.. example... $query = $db->execute("SELECT quantity FROM items WHERE player_id='$player->id'") $rcount = (all quantitys added together). there is already this but its not allowing me to use it in a equation... $rcount = $db->execute("SELECT SUM(quantity) AS `` FROM `items` WHERE `player_id` = '".$player->id."'"); Quote Link to comment Share on other sites More sharing options...
seany123 Posted November 26, 2009 Author Share Posted November 26, 2009 IS NO ONE ABLE TO HELP ME HERE??.... anyone know any other forum where i can get some help? Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted November 26, 2009 Share Posted November 26, 2009 listen dude .. this is a free forum (free for you to seek help/advice), and the people with whom you seek advice, are volunteering their time/efforts/advice. volunteering means, work for free. so, there are several reasons why nobody is helping you. 1. your problem does not interest anybody. 2. you have no retainer on anybody, nor do you employ anybody here .. therefore, nobody ahs an obligation to help you. 3. perhaps you've just annoyed people by having made the last 6 posts in your own thread. now it's a spite thing? anyways, firing out an indirect threat as so, "anyone know any other forum where i can get some help?", might have worked on ones' mom as a child, but i don't believe that will raise any concern around here. most of these guys know their stuff, and if asked nicely, they will help you. if nobody responds to your thread(s), refer to points 1, 2, and 3 again. and if you want something done sooooooo badly, perhaps coughing up a few buckos will spark some interest. but as long as you're seeking free help, you have to be more patient than that. seriously. $db->execute(); will return true on success, and false on fail. so, right off the bat, you are going to get unexpected results as you have it. regardless, you are setting SUM(quantity) AS `` .. you cannot get the SUM of anything if you set its alias to nothing. i'm assuming you're using ADODB? i'm not familiar with it, but you can try this: $rcount = $db->GetAll("SELECT SUM(`quantity`) AS `count` FROM `items` WHERE `player_id` = '".$player->id."'"); echo $rcount['count']; 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.