Jump to content

[SOLVED] Strange integer and variable problem..


JaTochNietDan

Recommended Posts

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  :o

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?

Archived

This topic is now archived and is closed to further replies.

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