PDA

View Full Version : how can add new field by db code


al3bed
02-16-2009, 02:17 PM
hello,

I have this code in my plugin:

$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 :)

Lynne
02-16-2009, 03:41 PM
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:
$id = $vbulletin->db->insert_id();

And then use $id.

al3bed
02-17-2009, 01:32 AM
you are great Lynne

thanks a lot :)

--------------- Added 1234846546 at 1234846546 ---------------

I have another problem :o

if I want to delete these rows I will use this:

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

Lynne
02-17-2009, 04:02 AM
$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.

al3bed
02-17-2009, 04:29 AM
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 ?

Dismounted
02-17-2009, 04:38 AM
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.

al3bed
02-17-2009, 05:17 AM
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. :D

Lynne
02-17-2009, 02:03 PM
It sounds like you will have to do a query to ask what the field id is before you go and delete the fields.