Jump to content
MakeWebGames

Recommended Posts

Posted

Heres the thing, i added an item to my game called a bank card, if you have it in your inventory it would give you double your interest rate in the bank, but fro some reason it won't work..

$i=$db->query("SELECT iv.*,i.* FROM inventory iv LEFT JOIN items i ON iv.inv_itemid=i.itmid WHERE iv.inv_itemid=18");
while($r=$db->fetch_row($i))
{
$user=($r['inv_userid']);
$db->query("UPDATE users SET bankmoney=bankmoney*(bankpercent*2)+bankmoney WHERE bankmoney > 0 AND bankmoney < bankmax+1 AND daysinactive < 2 AND userid=$user");
}
$db->query("UPDATE users SET bankmoney=bankmoney*bankpercent+bankmoney WHERE bankmoney > 0 AND bankmoney < bankmax+1 AND daysinactive < 2 AND userid!=$user");

 

It's prolly a very simple fix, but i'm not seeing it yet..

Posted

Re: Cron Help

Well basicly what you are doing is using a while function. So there for if i have 10 of the item's ill get 10x my interest rate.

Here is a better sollution.

 

$i = $db->query("SELECT inv_id,inv_userid FROM `inventory` WHERE `inv_itemid` = 18");
while($r = $dk->fetch_row($i))
{
   $user = $r['inv_userid'];
   $db->query("UPDATE `users` SET `bankmoney` = `bankmoney` * (`bankpercent` * 2 ) + `bankmoney` WHERE (`bankmoney` > 0 AND `bankmoney` < (`bankmax` + 1) AND `daysinactive` < 2) AND `userid` = ".$user);
   $db->query("UPDATE `users` SET `bankmoney` = `bankmoney` * (`bankpercent` + `bankmoney` WHERE (`bankmoney` > 0 AND `bankmoney` < (`bankmax` + 1) AND `daysinactive` < 2) AND `userid` <> ".$user);
}

 

Try that and see what happen's.

Posted

Re: Cron Help

QUERY ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE (`bankmoney` > 0 AND `bankmoney` < (`bankmax` + 1) AND `daysinactive` < 2)' at line 1

Query was UPDATE `users` SET `bankmoney` = `bankmoney` * (`bankpercent` + `bankmoney` WHERE (`bankmoney` > 0 AND `bankmoney` < (`bankmax` + 1) AND `daysinactive` < 2) AND `userid` <> 1

Posted

Re: Cron Help

 

$i = $db->query("SELECT inv_id,inv_userid FROM `inventory` WHERE `inv_itemid` = 18");
while($r = $dk->fetch_row($i))
{
   $user = $r['inv_userid'];
   $db->query("UPDATE `users` SET `bankmoney` = `bankmoney` * (`bankpercent` * 2 ) + `bankmoney` WHERE (`bankmoney` > 0 AND `bankmoney` < (`bankmax` + 1) AND `daysinactive` < 2) AND `userid` = ".$user);
   $db->query("UPDATE `users` SET `bankmoney` = `bankmoney` * (`bankpercent` + `bankmoney`) WHERE (`bankmoney` > 0 AND `bankmoney` < (`bankmax` + 1) AND `daysinactive` < 2) AND `userid` <> ".$user);
}

 

Missed a )

Posted

Re: Cron Help

Userid 1 and 2 have a item id 18, userid 1 gets the normal interest rate, but userid 2 gets more

Both accounts should get 4% interest, but userid 2 had $100 in the bank before i ran the cron, and $1040000 in the bank after i ran the cron.

Posted

Re: Cron Help

try this maybe for both users:

 

$i = $db->query("SELECT inv_id,inv_userid FROM `inventory` WHERE `inv_itemid` = 18");
while($r = $dk->fetch_row($i))
{
   $db->query("UPDATE `users` SET `bankmoney` = `bankmoney` * (`bankpercent` * 2 ) + `bankmoney` WHERE (`bankmoney` > 0 AND `bankmoney` < (`bankmax` + 1) AND `daysinactive` < 2) AND `userid` = ".$r['inv_userid);
   $db->query("UPDATE `users` SET `bankmoney` = `bankmoney` * (`bankpercent` + `bankmoney`) WHERE (`bankmoney` > 0 AND `bankmoney` < (`bankmax` + 1) AND `daysinactive` < 2) AND `userid` <> ".$r['inv_userid']);
}

 

Play around with the code between SET $l WHERE and figure it out maybe a little bit?

Posted

Re: Cron Help

 

$get_it = mysql_query("SELECT inv_itemid, inv_userid FROM inventory WHERE inv_itemid = 18");
if(mysql_num_rows($get_it) > 0)
{
$tru = mysql_fetch_array($get_it))
{
	$do_it = sprintf("UPDATE users SET bankmoney = bankmoney * (bankpercent * 2) + bankmoney WHERE bankmoney > 0 AND bankmoney < bankmax + 1 AND daysinactive < 2 AND userid = %u",($tru['inv_userid']));
	mysql_query($do_it);
}
}
else
{
mysql_query("UPDATE users SET bankmoney = bankmoney * (bankpercent + bankmoney) WHERE bankmoney > 0 AND bankmoney < bankmax` + 1 AND daysinactive < 2");	
}

 

this maybe?? i assume that your bankpercent and such are there somewhere already.....

just a shot in the wind.....

Posted

Re: Cron Help

None of these worked correctly,

Would adding an extra field to the users table say 'bankcard'

Then at the top of day cron add the item check, update the 'bankcard' to either 1 or 0

and add an additional WHERE to the interest query like:

UPDATE users SET bankmoney=bankmoney*(bankpercent*2)+bankmoney WHERE bankmoney > 0 AND bankmoney < bankmax+1 AND daysinactive < 2 AND bankcard > 0

UPDATE users SET bankmoney=bankmoney*bankpercent+bankmoney WHERE bankmoney > 0 AND bankmoney < bankmax+1 AND daysinactive < 2 AND bankcard < 1

Something like that would work?

I know adding another field to the users table is noobish but it's to only way i can think of right now.

Posted

Re: Cron Help

see im not sure its us or you......

Do you have bankpercent defined somewhere? in the users table i would hope and also bankmax daysinactive all needs to be defined somewhere? are they?

Posted

Re: Cron Help

Yes, they are all in the users table, every time someone buys a better bank they get a certain percentage, and their bank can only hold so much, anti-inflation tool.

  • 2 weeks later...
Posted

Re: Cron Help

 

Yes, they are all in the users table, every time someone buys a better bank they get a certain percentage, and their bank can only hold so much, anti-inflation tool.

what you could do is create another entire bank calling it a different name and set it in users as a another field then code the original bank to change the caculation of the interest to what your wanting to do, then have it check for the variable you want to run the new.php whatever you called it under the right conditions.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...