MyBB Community Forums

Full Version: Profilefields ID - Plugin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Im tyring to manually add a profile ID to a new profilefield that my plugin is creating, i dont what to auto-increment , i want to select a specific ID.

At the end of my profilefield within my plugin im using this to insert it:
$db->insert_query("profilefields", $newprofile);
$fid = $db->insert_id();
Ive tried :
$fid = 100;

Any ideas ?
If you want to create the profile field within your plugin, you should do it exactly the same way MyBB does it, not using your own method. Hardcoding IDs is a bad idea, particularly in this case since profile field ids are kind of special. They actually create new columns in the table that holds the profile field data. Which is ugly database design, but that's how it is. Using an ID like 100 out of the blue is not something you should do.

Suggestion: Have the user create the profile field, and make the field id a setting of your plugin.

This requires some minor manual labor on the users part but saves you a ton of headaches.
I disagree to a certain point. If a user creates a profile field manually and deletes it , then creates another profile field and so on .... the ID is incremented each time. So if this happens loads of times eventually a profile field will have an ID of 100 (doubtful but possible) , even though there might only be 5 or 6 profile fields, so is that not the same thing really ?

So i personnaly dont think giving it a set ID is a problem. So is it possible to hardcode an ID ?
Anyone ?
As far as good coding practices go, don't hard code it. You should grab the added ID and store it somewhere you can retrieve it later. It will perhaps be more annoying to code, however this is perhaps the "proper" solution, and really, what separates good code from bad code.
Cheers for the advice yumi Wink