Forum Moderators: coopster

Message Too Old, No Replies

Cron Job Update

         

dkin

8:50 am on Jan 7, 2005 (gmt 0)

10+ Year Member



I have a script, I would like it to be run by a cron job every half hour, this script will greatly effect my databases so I do not want anyone else to see it. Is there anyway I can password protect it and allow the cron job to get around the protection?

Also, I would like this script to add 1 to every number in a certain column in every row, all I can get thus far is it adds 1 to the first row then updates the rest of the rows with the first row value, I want it to add 1 to each unique number in each row

so

if we had three rows

245
352
634

they would become

246
353
635

not

246
246
246

Thanks all

dreamcatcher

9:32 am on Jan 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about putting your file outside your root directory?

dkin

6:00 pm on Jan 7, 2005 (gmt 0)

10+ Year Member



that may be able to work, what aboiut adding + 1 to each row individually, anyone know how to accomplish that?

dmorison

6:07 pm on Jan 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Adding 1 to an entire column should be just...

UPDATE table SET field = field + 1;

How are you trying to do it?

dkin

9:26 pm on Jan 8, 2005 (gmt 0)

10+ Year Member



the way I am doing it it is taking the value from the first row that it updates and inserting that value into every other row.

I do not have the code on me because I am not at home but when I get home tomorrow evening I will post it, if you have any suggestions until that time please feel free to post them.

dkin

6:04 am on Jan 10, 2005 (gmt 0)

10+ Year Member



This is the cde that I have been using.

##Connect to User Database
$uresult = mysql_query("SELECT * FROM user_char", $link) or die ("query 1: " . mysql_error());
$urow = mysql_fetch_array($uresult) or die ("query 2: " . mysql_error());
while{
$turns = ++$urow[turns];

##Update the database
$eresult = mysql_query("UPDATE user_char set turns = '$turns' where username = '$urow[username]'", $link);
}
if ($eresult == TRUE)
{
echo 'Updated successfully';
}
else
{
echo 'turn update failed';
}

But it is taking the value from the first row and adding 1 to it then inserting that value into every other row.

Anyone know what I am doin wrong?

jatar_k

10:17 pm on Jan 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



did you try using dmorison's suggestion? You should be able to fire that single query and update the whole column.

jshpro2

1:43 am on Jan 11, 2005 (gmt 0)

10+ Year Member



I see these people coding 'turn based games' all the time, no idea how they work, but if a turn is every 30 minutes why not just look at the value returned by time(), then subtract the timestamp of when the first turn took place and then divide by the amount of seconds in a half hour, then floor() it, make this a function and call it to see what turn it's on. This way you only store the timestamp of each users first turn in the DB, no cron jobs, and mySql can focus on more important things, you also don't have to worry about users not getting their 'turns' incremented right away (if your update script takes 5 minutes to run the last users will experience delayed update times)

I guess if your database isn't that large your way isn't an issue, but if your site gets too big you will need a more efficient way.

:-)

dkin

1:49 am on Jan 11, 2005 (gmt 0)

10+ Year Member



this technique is interesting, could you please explain it a touch more.