in reply to Daily Actions

Spidy:

I'm not a MySQL maven, so I'm going to pretend that you said "Sybase" and leave the conversion effort as an exercise for the reader.... 8^)

First, using your basic idea, you could (on login) compute the number of turns they get for the day. (I'd put a maximum on it, so if they don't log in for a long time they don't get too many turns for a day.) It seems like an appropriate task for the database, so you could do something like this. Given tables something like:

create table users ( user_id varchar(10) primary key, ... --standard junk you already have here turns_left int default 0, last_turn datetime default getdate() ) create table misc ( tag varchar(32) primary key, val varchar(128) ) go insert misc (tag, val) values ('Turns_Per_Day', '5') insert misc (tag, val) values ('Max_Turns_Allowed', '15')
You could use the following procedure when they log into the system:

create proc compute_turns_left @user_id varchar(10) as declare @days integer, @turns, @turns_per_day, @max_turns -- Read the configuration variables select @turns_per_day = isnull(convert(int, val), 1) from misc where tag='Turns_Per_Day' select @max_turns = isnull(convert(int, val), 1) from misc where tag='Max_Turns_Allowed' -- How many days since they last used a turn? select @days=datediff(d,getdate(),last_turn) from users where user_id=@user_id -- Update their turns update turns_left = turns_left + @days * @turns_per_day from users where user_id=@user_id -- And apply the limit cap update turns_left = @max_turns from users where user_id=@user_id and turns_left > @max_turns go
and this one every time they take a turn:
create proc consume_turn @user_id varchar(10) as update users set turns_left = turns_left-1, last_turn=getdate() where user_id=@user_id go
I hope you find this useful.

...roboticus