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 02-16-2009, 02:17 PM
al3bed's Avatar
al3bed al3bed is offline
 
Join Date: Sep 2006
Location: Bahrain
Posts: 190
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default how can add new field by db code

hello,

I have this code in my plugin:

PHP Code:
$vbulletin->db->query_write(
            INSERT INTO `"
TABLE_PREFIX ."profilefield` 
            (`profilefieldid` ,`profilefieldcategoryid` ,`required` ,`hidden` ,`maxlength` ,`size` ,`displayorder` ,`editable` ,`type` ,`data` ,`height` ,`def` ,`optional` ,`searchable` ,`memberlist` ,`regex` ,`form` ,`html` ,`perline`) 
            VALUES (NULL, '0', '0', '0', '16', '16', '', '1', 'input', NULL , '0', '0', '0', '0', '0', '', '0', '0', '0') 
        "

this is work to bulid field but without title and desc.
and another thing : I want displayorder column = profilefieldid like when I add a field by admincp/profilefield.php

I try to insert phrase to be like this:
varname: fieldx_title (which x is field id but I don't know how to find it)
fieldname: cprofilefield


I need help please
Reply With Quote
  #2  
Old 02-16-2009, 03:41 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Did you try looking at the code that vb uses when creating a profile field?

After you insert the profilefield, you may grab the profilefield id:
PHP Code:
$id $vbulletin->db->insert_id(); 
And then use $id.
Reply With Quote
  #3  
Old 02-17-2009, 01:32 AM
al3bed's Avatar
al3bed al3bed is offline
 
Join Date: Sep 2006
Location: Bahrain
Posts: 190
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

you are great Lynne

thanks a lot

--------------- Added [DATE]1234846546[/DATE] at [TIME]1234846546[/TIME] ---------------

I have another problem

if I want to delete these rows I will use this:
PHP Code:
$db->query_write("
            DELETE FROM " 
TABLE_PREFIX "profilefield 
            WHERE profilefieldid = " 
$id
            
);
        
$db->query_write("
            DELETE FROM " 
TABLE_PREFIX "phrase
            WHERE fieldname = 'cprofilefield' AND
            varname IN ('field" 
$id "_title', 'field" $id "_desc')
        "
); 
but it's not working?!

is that becuase $id is not recognized ? cause the first code in install code section and this one in uninstall code ?
Reply With Quote
  #4  
Old 02-17-2009, 04:02 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

$id just grabs the id of the last row entered into the database. So, you can only use it if you just added a row into the database and then grabbed the id of that row. Install and Uninstall queries are not run one after the other. They are totally separate because you are either installing or uninstalling.
Reply With Quote
  #5  
Old 02-17-2009, 04:29 AM
al3bed's Avatar
al3bed al3bed is offline
 
Join Date: Sep 2006
Location: Bahrain
Posts: 190
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ok, but I need that id to use it with other plugin in my product is there an method to save it?

like $myid = $id ?
Reply With Quote
  #6  
Old 02-17-2009, 04:38 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The ID is usually provided by the user or another database field (e.g. a user clicking a link). Not sure what you're trying to achieve.
Reply With Quote
  #7  
Old 02-17-2009, 05:17 AM
al3bed's Avatar
al3bed al3bed is offline
 
Join Date: Sep 2006
Location: Bahrain
Posts: 190
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hi Dismounted and thanx

I want to build a user field automaticly when my product is uploaded via plugins system. I success to build it gree Lynne.

Now I can't use the information inside the field if I don't know the id? you got it!

I succeed to build a full field with title and desc because id help me .. now I want that id to be with me all the time not just after added a row.. This is my problem.
Reply With Quote
  #8  
Old 02-17-2009, 02:03 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It sounds like you will have to do a query to ask what the field id is before you go and delete the fields.
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:47 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05435 seconds
  • Memory Usage 2,238KB
  • 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_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)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_postinfo_query
  • fetch_postinfo
  • 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