...

View Full Version : Troubles with SQL statment and array.



king2k5
03-04-2009, 06:52 PM
What i have is an online game. You get an income every "tick". That works fine. There was a recent update of income limits. Right now, once you reach your limit, the ticker script will reset your income if it goes over. This is not what i want. I want the income giving SQL statment to be bypassed if you are at your limit. So if you manage to get excess resources, you will not lose them. The code right now is:


<?
/* resource income */
foreach($income["res1"] as $key=>$value) {
mysql_query("UPDATE userinf SET r_res1=r_res1+".$income["res1"][$key]."+(".$multip["res1"][$key]."*a_res1) WHERE b_res1=$key ", $db);
}
foreach($income["res2"] as $key=>$value) {
mysql_query("UPDATE userinf SET r_res2=r_res2+".$income["res2"][$key]."+(".$multip["res2"][$key]."*a_res2) WHERE b_res2=$key ", $db);
}
foreach($income["res3"] as $key=>$value) {
mysql_query("UPDATE userinf SET r_res3=r_res3+".$income["res3"][$key]."+(".$multip["res3"][$key]."*a_res3) WHERE b_res3=$key ", $db);
}
foreach($income["res4"] as $key=>$value) {
mysql_query("UPDATE userinf SET r_res4=r_res4+".$income["res4"][$key]."+(".$multip["res4"][$key]."*a_res4) WHERE b_res4=$key ", $db);
}

/* Set Store Limit Resources */

$store_q = mysql_query("SELECT * FROM userinf");

$store = array(50000, 250000, 1000000, 10000000, 100000000, 250000000, 500000000);

while($row = mysql_fetch_array($store_q)) {
if($row['r_res1'] > $store[$row['store_level']]) {
mysql_query("UPDATE userinf SET r_res1 = ".$store[$row['store_level']]." WHERE username='".$row['username']."'");
}

if($row['r_res2'] > $store[$row['store_level']]) {
mysql_query("UPDATE userinf SET r_res2 = ".$store[$row['store_level']]." WHERE username='".$row['username']."'");
}

if($row['r_res3'] > $store[$row['store_level']]) {
mysql_query("UPDATE userinf SET r_res3 = ".$store[$row['store_level']]." WHERE username='".$row['username']."'");
}

if($row['r_res4'] > $store[$row['store_level']]) {
mysql_query("UPDATE userinf SET r_res4 = ".$store[$row['store_level']]." WHERE username='".$row['username']."'");
}
}
?>

Is there anyway to take the income SQL statments, and put in something like...

<?
$store = array(50000, 250000, 1000000, 10000000, 100000000, 250000000, 500000000);

foreach($income["res1"] as $key=>$value) {
mysql_query("UPDATE userinf SET r_res1=r_res1+".$income["res1"][$key]."+(".$multip["res1"][$key]."*a_res1) WHERE b_res1=$key AND r_res1<".$store[store_level]."", $db);
}
?>

The above obviously does not work. Any suggestions would be amazing. Thanks in advance :)

EDIT: The "store_level" inside the $store array is the value in the Database that would have a value of 0 - 6



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum