vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Member Archives (https://vborg.vbsupport.ru/forumdisplay.php?f=202)
-   -   LAST_INSERT_ID call (https://vborg.vbsupport.ru/showthread.php?t=35240)

TECK 02-20-2002 12:54 AM

i want to call in settinggroup the last settinggroupid (for example, 32 that i just created in settinggroup with a NULL). here what i came up with:
PHP Code:

$settinggroupid=$DB_site->query("SELECT LAST_INSERT_ID() FROM settinggroup");
$DB_site->query("INSERT INTO setting VALUES (NULL,$settinggroupid,'News forum ID','newsforumid','15','The specified forum will contain threads viewed on the main page only.','',0)"); 

it doesnt want to grab it... hmmmm.. i'm upset :noid:

the script returns this:
---------------------------------------
INSERT INTO setting VALUES (NULL,Resource id #6,'News forum ID','newsforumid','15','The specified forum will contain threads viewed on the main page only.','',0)

instead of:
---------------------------------------
INSERT INTO setting VALUES (NULL,32,'News forum ID','newsforumid','15','The specified forum will contain threads viewed on the main page only.','',0)

Scott MacVicar 02-20-2002 06:32 AM

PHP Code:

$settinggroupid=$DB_site->query_first("SELECT LAST_INSERT_ID() FROM settinggroup"); 

Put the values from the query into an array then it will work

Admin 02-20-2002 12:18 PM

Just use $DB_site->last_insert().

TECK 02-20-2002 11:51 PM

is not working PPN.. it returns Array instead of the value.

FireFly, can you post the exact line please? i need to make a query on this. here it is what i try to do:
PHP Code:

$DB_site->query("INSERT INTO settinggroup (settinggroupid,title,displayorder) VALUES (NULL,'".addslashes($title)."','$displayorder')");
echo 
"Adding settinggroup data... Done. <font color='#006699'>settinggroup</font> table populated.<br>\n";

$settinggroupid=$DB_site->query_first("SELECT LAST_INSERT_ID() FROM settinggroup");
$DB_site->query("INSERT INTO setting VALUES (NULL,$settinggroupid,'News forum ID','newsforumid','15','The specified forum will contain threads viewed on the main page only.','',0)");
echo 
"Adding setting data... Done. <font color='#006699'>setting</font> table populated.<p></td>\n"

i need to call the last ID from settinggroup and insert it as a value into setting. let me know where i do it wrong.

Scott MacVicar 02-21-2002 06:25 AM

Yes it returns an array, thats how you get data from the database, or you fetch row or fetch object.

use $settinggroupid[LAST_INSERT_ID()] as you said its an array. If your ever curious to what value an array holds you can use print_r($array);
and it will print out all the values of $array.

Anyway you can use $DB_site->insert_id(); to use the abstraction layer if you want.

its part of the abstraction layer which simply uses mysql_insert_id(); which is a nice trait of mysql as it gets the last value of the auto incrememnt column.

TECK 02-21-2002 06:40 AM

Quote:

Originally posted by PPN
Anyway you can use $DB_site->insert_id(); to use the abstraction layer if you want.
i'm confused about one thing, how do i call it from settinggroup? if i use:
PHP Code:

$settinggroupid=$DB_site->insert_id(); 

it will not grab the last id from settinggroup, right? help me understand better this matter.

btw scott, ty for your tips. i learn alot from mysql.com site, but you guys have all kind of tricks.. ;)

Admin 02-21-2002 10:00 AM

The bit of code you posted is correct nakkid.
mysql_insert_id() returns the last auto-increment ID that was insert into the DATABASE during the current connection.

Scott MacVicar 02-21-2002 03:04 PM

use this

PHP Code:

$DB_site->query("INSERT INTO settinggroup (settinggroupid,title,displayorder) VALUES (NULL,'".addslashes($title)."','$displayorder')");
echo 
"Adding settinggroup data... Done. <font color='#006699'>settinggroup</font> table populated.<br>\n";

$settinggroupid=$DB_site->insert_id();
$DB_site->query("INSERT INTO setting VALUES (NULL,$settinggroupid,'News forum ID','newsforumid','15','The specified forum will contain threads viewed on the main page only.','',0)");
echo 
"Adding setting data... Done. <font color='#006699'>setting</font> table populated.<p></td>\n"


TECK 02-21-2002 11:22 PM

thanks alot PPN... i posted a thread in Website Feedback. let me know if i'm crazy.. read more in my signature why i decide not to post any hacks anymore here.

however, i will give you a copy of the script once completed, so you can use it. i will keep in touch here through pm's and email.

thanks alot for all your support (scott and chen).


All times are GMT. The time now is 04:43 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.01060 seconds
  • Memory Usage 1,745KB
  • 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
  • (5)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)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