JaTochNietDan Posted March 2, 2009 Share Posted March 2, 2009 function FamilyNetworth($Family) { $result = mysql_query('SELECT username,networth FROM `users` WHERE family = "'.$Family.'"'); $Total = 0; if(mysql_num_rows($result) == 0) { echo 'None found'; } while($row = mysql_fetch_array($result)) { $UCash = $row['networth']; $Total + $UCash; } return $Total; } Does anyone see whats wrong with that? Its so annoying, it just returns 0 every single time no matter what the values that are being added. The only way I ever get a different value is if I change the $Total = Variable at the top of the function Link to comment https://forums.phpfreaks.com/topic/147494-solved-strange-integer-and-variable-problem/ Share on other sites More sharing options...
cooldude832 Posted March 2, 2009 Share Posted March 2, 2009 this line <?php $Total + $UCash; ?> should be <?php $Total += $UCash; ?> Link to comment https://forums.phpfreaks.com/topic/147494-solved-strange-integer-and-variable-problem/#findComment-774242 Share on other sites More sharing options...
JaTochNietDan Posted March 2, 2009 Author Share Posted March 2, 2009 .... Oh my god. lol. Thanks Link to comment https://forums.phpfreaks.com/topic/147494-solved-strange-integer-and-variable-problem/#findComment-774243 Share on other sites More sharing options...
cooldude832 Posted March 2, 2009 Share Posted March 2, 2009 Now the real answer is that is a poor way to do it better way is <?php function FamilyNetworth($Family){ $q = "SELECT SUM(networth) as cash from `users` Where Family = '".mysql_real_escape_string($Family)."'"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) >0){ $row = mysql_fetch_assoc($r); return $row['cash']; } else{ echo "No Family Found"; return NULL; } } ?> Questions? Link to comment https://forums.phpfreaks.com/topic/147494-solved-strange-integer-and-variable-problem/#findComment-774245 Share on other sites More sharing options...
JaTochNietDan Posted March 2, 2009 Author Share Posted March 2, 2009 I will take your PHP coding advice into consideration Link to comment https://forums.phpfreaks.com/topic/147494-solved-strange-integer-and-variable-problem/#findComment-774266 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.