Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-23-2005, 01:37 PM
HakkieDEV HakkieDEV is offline
 
Join Date: Jun 2004
Posts: 62
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Creating a cronjob

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?
Reply With Quote
  #2  
Old 01-23-2005, 01:42 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i have to go out for a few hours but i'll write the code for you when i come back
Reply With Quote
  #3  
Old 01-23-2005, 01:44 PM
HakkieDEV HakkieDEV is offline
 
Join Date: Jun 2004
Posts: 62
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by sabret00the
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.
Reply With Quote
  #4  
Old 01-23-2005, 01:50 PM
miz miz is offline
 
Join Date: Mar 2003
Posts: 416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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..
Reply With Quote
  #5  
Old 01-23-2005, 02:01 PM
HakkieDEV HakkieDEV is offline
 
Join Date: Jun 2004
Posts: 62
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by miz
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:

[sql]
$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");
[/sql]

However, this only works for 1 user per time.

I would like the same formula, but it should do this for ALL users.
Reply With Quote
  #6  
Old 01-23-2005, 05:15 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

[sql]UPDATE user SET contributionpoints=posts + helppoints * 3;[/sql]
Reply With Quote
  #7  
Old 01-23-2005, 05:19 PM
HakkieDEV HakkieDEV is offline
 
Join Date: Jun 2004
Posts: 62
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MarcoH64
[sql]UPDATE user SET contributionpoints=posts + helppoints * 3;[/sql]
Oh my god, tell me it isn't that simple? /me == stupid.

It is definitly this simple.

I'm shocked.

Thanks a bunch, I was thinking about much more difficult solutions.
Reply With Quote
  #8  
Old 01-23-2005, 06:01 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #9  
Old 01-23-2005, 06:16 PM
HakkieDEV HakkieDEV is offline
 
Join Date: Jun 2004
Posts: 62
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MarcoH64
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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:18 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08456 seconds
  • Memory Usage 2,239KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete