Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Posts
    189
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Troubles with SQL statment and array.

    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:

    PHP Code:
    <?
    /* 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(50000250000100000010000000100000000250000000500000000);

    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...
    PHP Code:
    <?
    $store 
    = array(50000250000100000010000000100000000250000000500000000);

    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
    Last edited by king2k5; 03-04-2009 at 07:54 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •