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

Reply
 
Thread Tools Display Modes
  #11  
Old 05-31-2006, 03:36 AM
sambah sambah is offline
 
Join Date: May 2006
Posts: 67
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The SQL query you want is this:

UPDATE `user` SET `usergroupid` = '#' WHERE `userid` =x LIMIT 1 ;


# should be set to whatever usergroupid you want the person to be in

x = the user id of the member being promoted

I hope this is right
Reply With Quote
  #12  
Old 05-31-2006, 04:01 AM
jwocky jwocky is offline
 
Join Date: Mar 2005
Posts: 138
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok using that info this is the php line I came up with:

PHP Code:
$vbulletin->db->query_write("UPDATE user SET usergroupid = '9' WHERE userid = '" $username "' LIMIT 1"); 
$username actually defines the userid#.. i've checked to make sure its right through an $echo statement beforehand..

anyways, this just doesnt work, this is the error I keep getting..

Fatal error: Call to a member function on a non-object on line 37
Reply With Quote
  #13  
Old 05-31-2006, 04:34 AM
sambah sambah is offline
 
Join Date: May 2006
Posts: 67
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try this.


Code:
		$db_select = @mysql_select_db($dbname,$db) or die('Mysql Database Failure');
 		$table_name = 'user';
 		$result = mysql_query("UPDATE  '.$table_name.' SET usergroupid = '9' WHERE userid = '" . $username . "' LIMIT 1") or die(mysql_error());

Sorry for the delay. I had to look that up on php.net

I only usually do databases, not PHP.

Let me know if it works
Reply With Quote
  #14  
Old 05-31-2006, 04:40 AM
jwocky jwocky is offline
 
Join Date: Mar 2005
Posts: 138
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Interesting.. well now it atleast gives me this as output

"Mysql Database Failure"

so atleast your new code is doing something. I wonder what the issue is, I will tinker.
Reply With Quote
  #15  
Old 05-31-2006, 04:42 AM
sambah sambah is offline
 
Join Date: May 2006
Posts: 67
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok that means its not connecting to the DB.

Try removing the $db_select line and tell me what it says
Reply With Quote
  #16  
Old 05-31-2006, 04:49 AM
jwocky jwocky is offline
 
Join Date: Mar 2005
Posts: 138
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

UPDATE!!! SUCCESS!!! I removed ure previous code for conneting the database and thats why it didnt work, as soon as I put that code back in, it seems to now conenct to the database and made the neccesary change in the usergroup permissions!! this is awesome.

Thanks so much. Ok now onto the next phase of this project.

Actually before I move on, does anyone know if there is another way to conenct to the database since I dont feel right putting in my database name and password into this php file, altho I guess its ok if noone knows where it is right ?
Reply With Quote
  #17  
Old 05-31-2006, 04:51 AM
sambah sambah is offline
 
Join Date: May 2006
Posts: 67
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yay! glad I could help a little!

You have the database details in the config.php file correct?
Reply With Quote
  #18  
Old 05-31-2006, 04:51 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you require() global.php, it basically "loads vBulletin". This gives you access to the database, user sessions, everything. Depending on what you are doing, you may or may not want this.

Anyway, whenever you see the database object ($db, $this->db, $vbulletin->db etc), it is going through vBulletin instead of just through MySQL.
PHP Code:
function comparestart($today$users)
{
    global 
$vbulletin;
    foreach (
$users as $user)
    {
        
// Just to keep things clear
        
$userid $user[0];
        if (
$today == $user[1])
        {
            
promote($userid);
        }
    }
}

function 
promote($userid)
{
    global 
$vbulletin;
    
    
$vbulletin->db->query_write("
        UPDATE " 
TABLE_PREFIX "user
        SET usergroupid = 9
        WHERE userid = 
$userid
    "
);
    
    echo 
"User $userid promoted!<br />";

Not much new here... the global keyword gives $vbulletin global scope, I assume you know what that means because you are passing everything into the functions properly. You could also pass it (by reference! we don't want to duplicate it) into the functions if you prefer that method.

My query is essentially the same, too. I added the constant TABLE_PREFIX before the table name, which is pretty much the standard now so it will work no matter what your prefix is (or isn't). There is no need to put 9 in quotes, as it is an integer. Unless you have a list of userids, you can simply check if left side = right side.
Reply With Quote
  #19  
Old 05-31-2006, 05:00 AM
sambah sambah is offline
 
Join Date: May 2006
Posts: 67
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Aha. I was wondering what all the $db, $this->db, $vbulletin->db etc malarky was
Reply With Quote
  #20  
Old 05-31-2006, 05:00 AM
jwocky jwocky is offline
 
Join Date: Mar 2005
Posts: 138
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ah-ha. Yes so it can be done using vbulletins own variables. Wow we have 2 equally great solutions in one thread, will be great for ppl looking in at this thread in the future using search. Ok, now to Step 4, coding the opposite.. The demotions
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 06:19 AM.


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.04342 seconds
  • Memory Usage 2,260KB
  • 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
  • (1)bbcode_code
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete