View Full Version : Creating a cronjob
HakkieDEV
01-23-2005, 01:37 PM
Hi
Inside the table user I have 3 fields, posts and helppoints, contributionpoints.
Now, I would like to have a cronjob do every 24 hours a calculation like this:
$posts+$helppoints*3=$contributionpoints.
Now, it should update all contributionpoints fields in the table user.
And, like you've guessed, I have totally no idea how to do that. Anyone willing to help me a bit?
sabret00the
01-23-2005, 01:42 PM
i have to go out for a few hours but i'll write the code for you when i come back :)
HakkieDEV
01-23-2005, 01:44 PM
i have to go out for a few hours but i'll write the code for you when i come back :)
Now that is a fast response!
I know how to make queryes/update/insert/etc, but I have no idea how to select data from multiple fields, then do some modifications with it and then update the table again.
It would be really helpfull.
Thanks in advance. :)
hmm
you mean use cornjob from admincp right ?
then write a php page that every time we run it its doing the update to query's
then just add it via admincp..
HakkieDEV
01-23-2005, 02:01 PM
hmm
you mean use cornjob from admincp right ?
then write a php page that every time we run it its doing the update to query's
then just add it via admincp..
Uhum, I know how to add a php file into the cronjob list in admincp.
I only have trouble in automating the process of selecting multiple fields and after modifications, inserting it again in multiple fields.
I know how to do it for a single field:
$single= $DB_site->query("SELECT posts, helppoints FROM user WHERE userid=6");
$posts = $single['posts'];
$helppoints = $single['helppoints'];
$contributionpoints = $posts + $helppoints*3;
$update=$DB_site->query_first("UPDATE user SET contributionpoints=$contributionpoints WHERE userid=6");
However, this only works for 1 user per time.
I would like the same formula, but it should do this for ALL users.
Marco van Herwaarden
01-23-2005, 05:15 PM
UPDATE user SET contributionpoints=posts + helppoints * 3;
HakkieDEV
01-23-2005, 05:19 PM
UPDATE user SET contributionpoints=posts + helppoints * 3;
Oh my god, tell me it isn't that simple? /me == stupid.
It is definitly this simple.
I'm shocked. :D
Thanks a bunch, I was thinking about much more difficult solutions.
Marco van Herwaarden
01-23-2005, 06:01 PM
Yes it is that simple ;)
It will for each row take the rows value for posts and helppoints, multiply by 3, then store back in the contributepoints for that same row. You could add a WHERE clause if you want it to limit to only some users.
HakkieDEV
01-23-2005, 06:16 PM
Yes it is that simple ;)
It will for each row take the rows value for posts and helppoints, multiply by 3, then store back in the contributepoints for that same row. You could add a WHERE clause if you want it to limit to only some users.
Thanks a lot mate, I already inserted a WHERE clause.
It working like a charm now.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.