vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Little help with yet another advanced query... (https://vborg.vbsupport.ru/showthread.php?t=41576)

JJR512 07-27-2002 02:43 AM

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"?

Admin 07-27-2002 05:06 AM

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.

JJR512 07-27-2002 05:12 AM

So I'd have to do it as a script, and not as a simple query straight to the db?

Admin 07-27-2002 05:30 AM

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;


Sparkz 07-27-2002 05:38 AM

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);


Sparkz 07-27-2002 05:40 AM

Umm, Chen... The board did some strange parsing when I posted that inside [sql ] instead of [code ]


All times are GMT. The time now is 11:20 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.02640 seconds
  • Memory Usage 1,715KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete