PDA

View Full Version : PHP Help!



Assassinator
22-08-2008, 05:21 PM
Ok, well basicly im coding a feature for my game, ive done most of it, i just need some help.

I want it so everynight at 12pm, it updates a random username from 'users' in the database.

Im not sure how to go about this, any help?

Johno
23-08-2008, 01:28 AM
I did try to write the code but at 2 in the morning, I was simply too tired too!

Someone else probably will and do it better but oh well!

Set an integer to randomly generate using rand();

Simply you use the date(h:i); function to grab the current server time (e.g - 12:21) and set that as a variable.

Then set the time you want the thing to occur as another variable - ($otime = '00:00';)

Then simply query the database ($query = mysql_query('SELECT id FROM users WHERE id = `$rand`');)

Then do mysql_num_rows to see if that id exists within the table.

then an if/else statement:

if ($num>0 && $time == $otime) {

// update

} else {

// redo using the same stuff as above

}

I think that method would work but I seriously have no idea at this time!

If I have time tomorrow and nobody else has, ill give it a go :)

Hypertext
23-08-2008, 01:44 AM
Running a recursive service on your server, will be annoying, and unreliable.

Alternatively, and much less resourcefully, you could create a cron job, which is a script that in *nix can be made to run every x, ask your webhost, of if you tell me who your web host is, i can try and walk you through it.

Want to hide these adverts? Register an account for free!