ukspudnie Posted April 28, 2008 Share Posted April 28, 2008 I'm trying to create a function which updates a score, as in adds the new score to the old.. one.. i'm using this function but it just seems to be replacing the current score with the new one not increasing it. //executes the command B $queryB = "select * from $tableB where agency = '$agency'"; $resB = mysql_query($queryB) or die("Data not found."); $rowB = mysql_fetch_array($resB, MYSQL_ASSOC); if(isset($rowB['agency'])){ // settype($rowB['totalTime'], 'float'); settype($finalTime, 'float'); settype($totalTime, 'float'); // if($rowB['agency'] = $agency){ mysql_query ("UPDATE `$tableB` SET `gameid` = '$gameid', `totalTime` += '$finalTime',`date` = '$date' WHERE `agency` = '$agency'"); } } else { //Generate New Agency mysql_query ("INSERT INTO $tableB (gameid,agency,totalTime,date) VALUES ('$gameid','$agency','$finalTime','$date')"); } It's an secret fbi agency type flash game.. we team members, fighting around a multi player environment, just want to keep track of the whole teams score.. any other quicker way would be welcome. Many thanks Link to comment https://forums.phpfreaks.com/topic/103257-solved-php-add-to/ Share on other sites More sharing options...
pocobueno1388 Posted April 28, 2008 Share Posted April 28, 2008 Instead of `totalTime` += '$finalTime' Do `totalTime` = totalTime + $finalTime Link to comment https://forums.phpfreaks.com/topic/103257-solved-php-add-to/#findComment-528858 Share on other sites More sharing options...
ukspudnie Posted April 28, 2008 Author Share Posted April 28, 2008 Nope that doesn't seem to work either.. Here's the amended code, now it doesn't even replace it.. it just doesn't do anything, I might have a syntax error somewhere.. <?php $tableB = "agencyboard"; //executes the command B $queryB = "select * from $tableB where agency = '$agency'"; $resB = mysql_query($queryB) or die("Data not found."); $rowB = mysql_fetch_array($resB, MYSQL_ASSOC); if(isset($rowB['agency'])){ // settype($rowB['totalTime'], 'float'); settype($finalTime, 'float'); settype($totalTime, 'float'); // if($rowB['agency'] = $agency){ mysql_query ("UPDATE `$tableB` SET `gameid` = `$gameid`, `totalTime` = totalTime + $finalTime,`date` = `$date` WHERE `agency` = `$agency`"); } } else { //Generate New Agency Listing. mysql_query ("INSERT INTO $tableB (gameid,agency,totalTime,date) VALUES ('$gameid','$agency','$finalTime','$date')"); } ?> Link to comment https://forums.phpfreaks.com/topic/103257-solved-php-add-to/#findComment-528873 Share on other sites More sharing options...
pocobueno1388 Posted April 28, 2008 Share Posted April 28, 2008 Okay, lets try this and see if there is an issue with the variables within the query. Also, you are using backsticks instead of a single quote around your variables. <?php if($rowB['agency'] = $agency){ $query = "UPDATE $tableB SET gameid = '$gameid', totalTime = totalTime + $finalTime, date = '$date' WHERE agency='$agency'"; $result = mysql_query($query)or die(mysql_error()."<p>With Query:<br>$query"); echo $query; } ?> Link to comment https://forums.phpfreaks.com/topic/103257-solved-php-add-to/#findComment-528932 Share on other sites More sharing options...
ukspudnie Posted April 28, 2008 Author Share Posted April 28, 2008 Many thanks, I just noticed that as you posted.. it's working great now..a fresh pair of eyes works wonders. I think i'm going to stick to action script. Many thanks you are a guru. Link to comment https://forums.phpfreaks.com/topic/103257-solved-php-add-to/#findComment-528944 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.