|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
need help with sceduling tasks
In my casual table i have a playable field. if it is 'o' they can play the game, if it is 'x' that means they are jailed. then if they are jailed i have a jaileddays field showing how many days they are jailed for.. everyday at reset i want it to go down a number obviously.. but i cant get it to! here is what i have
<cfquery name="jailstuff" datasource="userlogin"> Select * from casual </cfquery> <cfoutput query="jailstuff"> <cfif playable is 'x'> <cfquery datasource="userlogin"> update Casual set jaileddays = jaileddays - 1 </cfquery> </cfif> </cfoutput> but first off it is update EVERYONE so if they are 'o' playable then it makes them go into the negatives, AND it makes everyone go down like 3 instead of 1.. ie, those at 8 days jailed, go down to 5... and those who arent even jailed go to -3.. :S |
|
#2
|
|||
|
|||
|
You could create a scheduled task to automatically update this. Use <cfschedule> or the CF administrator.
However, this seems *really* inefficient. Why not just set a value in the table with a date stamp of when their "jail time" expires, and then at any time you can calculate the difference between the current time and the end of the jail time to determine how much longer they'll be in jail. Updating this value for every user for every day seems like overkill.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
umm i am doing this in the sceduled tasks part of cf administrator, if thats what you meant.. i am new to cf so i dont know about how to do a timestamp and stuff yet so i am just trying it this way - is that possible?
Quote:
|
|
#4
|
|||
|
|||
|
It would be possible to have a scheduled task update the database every day (or on whatever schedule you set). However, like I said it really is an inefficient method. I mean, if the system had 10,000 entities you'd be updating all 10,000 of them every day just to subtract 1 from one of the columns. So...possible? Yes. Efficient? Definitely not.
I'd try to look into comparing dates instead. |
|
#5
|
|||
|
|||
|
well do you know what is wrong with my current code since its not working properly?
|
|
#6
|
|||
|
|||
|
Maybe something like:
<cfquery datasource="userlogin"> update Casual set jaileddays = jaileddays - 1 where jaileddays > 0 </cfquery> |
|
#7
|
|||
|
|||
|
That worked
One last question -about sheduling tasks..
I have the battle table with fields like HP and stuff but then im trying to update the user_id's information in another table with info from the battle table battle: user_id hp: Table: user_id: field: im trying to get their hp from the hp field, and put it in the "field" field... <cfquery name="gethp" datasource="userlogin"> Select * from battle </cfquery> <cfoutput query="gethp"> <cfquery datasource="userlogin"> update Table set field = #hp# </cfquery> it's setting everyone to 50 in the second table, when not everyone has 50 HP in the battle table... what can i do :S </cfoutput> |
|
#8
|
|||
|
|||
|
It seems like you need to look into SQL some more...I highly recommend Ben Forta's SQL in 10 Minutes, it's very cheap, small, and packed with good stuff.
I'd try something like this: <cfquery datasource="userlogin"> update Table t, Battle b. set t.field = b.hp where t.user_id = b.user_id </cfquery> However this seems like overkill, is there a reason why you would want to duplicate the HP field into the other table? Duplication is evil and when you see it this should trigger a red flag in your mind. |
|
#9
|
|||
|
|||
|
If you saw my game you'd know. I have two different battle systems and they are completely different, but require the same HP. They are not connected in any way except that, so.. that's how it has to be done. Thanks for the code though i will try it now.
Quote:
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > need help with sceduling tasks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|