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 07-27-2002, 03:43 AM
JJR512's Avatar
JJR512 JJR512 is offline
 
Join Date: Oct 2001
Location: Glen Burnie, MD, USA
Posts: 710
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Little help with yet another advanced query...

Suppose I want to add a new settinggroup and settings to the vBulletin Options section of the admin cp. I know that to do this, I add a new record to the settinggroup table, like so: INSERT INTO settinggroup (settinggroupid,title,displayorder) VALUES (xx,"Group Title",xx);. I also know that to add settings to that setting group, I would use something like: INSERT INTO setting (settingid,settinggroupid,title,varname,value,desc ription,optioncode,displayorde r) VALUES (nn,xx,"Setting Name","$varname","1","Description about setting","yesno",yy);.

Now my question is, if I use NULL for xx while creating the settinggroup so that it takes the next auto-increment number, is there a way I can do the second query, making the setting, so that it uses the same number for xx? Some kind of join or something where it looks in settinggroup for a settinggroupid where the title equals "Group Title"?
Reply With Quote
  #2  
Old 07-27-2002, 06:06 AM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

After running the first query (INSERT INTO settinggroup), do this:
Code:
$newSettingGroupID = $DB_site->insert_id();
// Same as mysql_insert_id();
And then use $newSettingGroupID as XX.
Reply With Quote
  #3  
Old 07-27-2002, 06:12 AM
JJR512's Avatar
JJR512 JJR512 is offline
 
Join Date: Oct 2001
Location: Glen Burnie, MD, USA
Posts: 710
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So I'd have to do it as a script, and not as a simple query straight to the db?
Reply With Quote
  #4  
Old 07-27-2002, 06:30 AM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You could run these two queries, one after another:
Code:
INSERT INTO settinggroup (settinggroupid,title,displayorder) VALUES (null,"Group Title",1);
INSERT INTO setting (settingid,settinggroupid,title,varname,value,description,optioncode,displayorder) SELECT null,LAST_INSERT_ID(),"Setting Name","varname","1","Description about setting","yesno",1 FROM settinggroup LIMIT 1;
Reply With Quote
  #5  
Old 07-27-2002, 06:38 AM
Sparkz's Avatar
Sparkz Sparkz is offline
 
Join Date: Nov 2001
Posts: 544
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is how I did the exact same thing in the installer of my Default PM-hack.
Code:
SELECT @displayorder:=displayorder+1 FROM settinggroup ORDER BY displayorder DESC LIMIT 1;
INSERT INTO settinggroup (title, displayorder) VALUES ('Default PM', @displayorder);
SELECT @settinggroupid:=LAST_INSERT_ID();
INSERT INTO setting (settinggroupid, title, varname, value, description, optioncode, displayorder)
       VALUES (@settinggroupid, 'Send default PM to new users?', 'defpmactive', '0', '', 'yesno', 1);
Reply With Quote
  #6  
Old 07-27-2002, 06:40 AM
Sparkz's Avatar
Sparkz Sparkz is offline
 
Join Date: Nov 2001
Posts: 544
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Umm, Chen... The board did some strange parsing when I posted that inside [sql ] instead of [code ]
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 05:49 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.04883 seconds
  • Memory Usage 2,206KB
  • Queries Executed 13 (?)
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
  • (3)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)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