I have some trouble for syncing the SQL and PHP value
if try running the code in multi-browsers ( say 10 ) in the same time
somehow some way 50001, or even 50002 pop up
anyone have any tip about it ?
<?
$conn = mysql_connect("localhost", "root", "pass");
mysql_select_db("test",$conn);
while (!$done) {
$sql = "SELECT * FROM `T`";
$result = mysql_query($sql, $conn) or die(mysql_error());
$newArray = mysql_fetch_array($result);
$id = $newArray['id'];
$i = $newArray['i'];
for( $x =0; $x <= 100;$x++); // simulate some job
if ($i < 50000) {
$sql = 'UPDATE `T` SET `i` = `i` + 1 WHERE `id` = 1 LIMIT 1';
// execute the SQL statement
if (!mysql_query($sql, $conn)) {
echo "something went wrong";
}
}else{
$done = true;
echo "DONE! i = ". $i;
}
}
?>