Jump to content

Which is faster?


StormTheGates

Recommended Posts

Ive always wondered this. There are two methods that Ive used, one in the past and now the newer one to update things. Here is my old way:

 

<?php
$train = mysql_query("SELECT soldiers, guards, workers, scientists FROM followerstats WHERE username='$username' AND family='$family'")or die("Something fucked up, contact Wolf!");
			while($success = mysql_fetch_row($train)){
				$usold = $success[0];
				$uguard = $success[1];
				$uwork = $success[2];
				$usci = $success[3];
			}
			$usold = $usold + $soldsgot;
			$uguard = $uguard + $guardsgot;
			$uwork = $uwork + $workersgot;
			$usci = $usci = $scisgot;
			$total = $usold + $uguard + $uwork + $usci;
			mysql_query("UPDATE followerstats SET soldiers='$usold', guards='$uguard', workers='$uwork', scientists='$usci', total='$total' WHERE username='$username' AND family='$family'")or die(mysql_error());
?>

And here is my new way:

[code]
<?php
$total = $total + $workersgot + $soldiersgot + $guardsgot + $scientistsgot;
mysql_query("UPDATE followerstats SET soldiers=soldiers+$soldiersgot, guards=guards+$guardsgot, workers=workers+$workersgot, scientists=scientists+$scientistsgot, total='$total' WHERE username='$username' AND family='$family'")or die(mysql_error());
?>

 

Which way is faster in the long run do you think? I am considering going through my code and converting things like the first method into things like the second method. Is this a good idea?[/code]

Link to comment
https://forums.phpfreaks.com/topic/107494-which-is-faster/
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.