Jump to content

[SOLVED] Php add to ..


ukspudnie

Recommended Posts

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

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

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

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.