Jump to content

[SOLVED] -Sorta- New To Php


Efrem

Recommended Posts

Ok well I took on a project, for learning purposes, to make a Text-Based RPG Game. So far I have the database completely setup and everything is working fine. But what I am searching for is how to update a value in a MySql DB every x amount of minutes. Now whether this is a Php question or a Sql question stumped me, because I just have no idea how I would do it, so I posted it here. Any help is appreciated! Thanks in advance.

 

- Efrem

Link to comment
https://forums.phpfreaks.com/topic/116541-solved-sorta-new-to-php/
Share on other sites

Mmmk ty.  Another question  ;D

 

mysql -h hostname -u username -p password -e "update mytable set status = archive where status = filed"

 

I have to double check that command line for Cron ^

 

Uhh now if that is correct how would i go about doing addition in that command line.. like...

 

100 Users

Every 10 Mins i want to add 10 turns to all of them.

 

I dont know Cron Job but google helped me out a bit, but not enough.

 

- Efrem

 

Edit -

 

I was trying things in my phpmyadmin.. so far i have this

UPDATE turns SET turns = turns + 10 FROM chivalry_rpg.characters WHERE turns >= 0

but it doesnt work for whatever reason, tried it like this too

UPDATE turns SET turns = turns + 10 FROM chivalry_rpg.characters

 

Ok i got it working, gonna try the cron command now

Your query is wrong.

try like this:

UPDATE turns SET turns = turns + 10  WHERE turns >= 0

Of course turns will be the table name.

 

Now about cronjob.

Can you provide more details.

1-Are you have Linux installed and want to test on that.

2-Are you have hosting which is in Linux.

3-You want to do this on server OR on your local PC.

4-Are you windows user.

I put my email into the cron job editor feature on my host, got this error:

 

Enter password: ERROR 1045 (28000): Access denied for user 'my_user'@'localhost' (using password: NO)

 

This is my Cron Command:

 

mysql -h localhost -u my_user -p my_password -e "UPDATE chivalry_rpg.characters SET turns = turns + 10"

 

@mmarif4u

1. I dont have linux

2. Not entirely sure if my host has Linux installed? I can run the Cron Job though it just shoots that error at me ^

3. On my host

4. Yes

Ok i got it to work. But now here is 1 last question.

 

Lets say i wanted to add a Cap to it like... Turns cant be more than Level * 100... how would i go about doing that?.. like lets say if..

 

Person X | Turns = 321 | Level = 4 | Cap Turns = 400

Person Y | Turns = 192 | Level = 2 | Cap Turns = 200

 

Now with the Cron it will constantly add 10 Turns every 10 Mins. How would i make it so that it just equals the Cap if its gonna go over it?

Cap Turns Is Not a value in my Table.

 

- Efrem

i didnot understand your question clearly.

But if you want to limit the Cap.You can use > OR < OR >= .something like which will check the Cap field.

 

Well I dont have the Cap Field created as i want it to be dynamic without having to do much work. So ill rephrase the question..

 

i want to do something like this:

 

if (turns + 10 >= level * 100) THEN SET turns = level*100 ELSE SET turns = turns +10

 

now i know you can use IF Else statements in sql commands.. but i have no idea how to do it correctly

 

- efrem

as mmarif4u suggested it will work, but what i intended , was not to retrieve the records but fire these queries back to back without checking anything.

 

This way it will update turns + 10. in some case it may go beyond levels * 100, but the second query will update those records to levels * 100

 

this means you need only total 2 queries..

 

if you select records and fire update for each seperately depending on the condition, it will require a lot of queries...

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.