View Full Version : Correct method to add extra fields to threads?
Razasharp
06-08-2008, 07:27 PM
I am thinking about adding some extra fields for threads and wondered what you all thought was the best way to go about it.
Should I add the fields to the existing thread table, or create a new table for these fields?
There will be around 6 or 7, however, not all forums will be using them, actually just a handful. So for the majority of threads they won't be needed. Also, the info in these extra fields won't even show on showthread - they are being added for internal use only, hence their data will be called in a custom script. (Although they will be added/updated by mods or admin via edit thread)
Most of the hacks here add them to the thread table, however, some hacks like GARS create a separate table. Hence I wondered what you thought the best, most efficient method is.
Also, is the information in this thread (https://vborg.vbsupport.ru/showpost.php?p=799179&postcount=12) still current?
Paul M
06-08-2008, 07:33 PM
From your description I would say create a new table with threadid as the key.
Razasharp
06-08-2008, 10:04 PM
Thanks Paul.
If you get two mins, can you give me some pointers or a rough outline on how I should go about it? I'll try to work out the details for myself (I'm still a php nube :lol:)
harmor19
06-08-2008, 11:51 PM
Firstly think of the fields you like to use on your new table. Of course there's the ID, thread ID and the question. You should also put a field for enable/disable.
I made a similar hack and you can look at it to see what hooks you need to use. https://vborg.vbsupport.ru/showthread.php?t=128587
I suggest creating another table that holds the user's ID, the question ID and their answer.
If you know how to use 'LEFT JOIN' then you do not need to make a field for "thread ID" but since you do not know that much you should add "thread ID".
Paul M
06-09-2008, 12:22 AM
If you get two mins, can you give me some pointers or a rough outline on how I should go about it? I'll try to work out the details for myself (I'm still a php nube :lol:)
Can you be a bit more specific on what you want to know.
Razasharp
06-09-2008, 01:05 AM
Harmor19 - thanks for the help :) (I think your hack works in a different way, whereby the 'fields' are actually forms, and the data entered simply gets appended to the post? If so any chance you doing one where the field data is stored in the db seperately? saves me the fuss and I could make a donation :D )
Paul - I was hoping for a general outline, but appreciate that's a bit too much to ask... prob easier if I post what I plan here and perhaps you guys can let me know if I'm on the right track or not?
So so far, I need a new table with fields. This seem ok? Have I missed anything? Do I need to index?
New table:
my_thread_fields
Fields:
ThreadID (key)
MYField 1
MYField 2
MYField 3
MYField 4
MYField 5
MYField 6
MYField 7
I will check out Harmor19's hack to see which bits are similar/I can learn from for the data to be input and updated through vB - I think this is where I'll get stuck the most!
Cheers,
harmor19
06-09-2008, 12:56 PM
Harmor19 - thanks for the help :) (I think your hack works in a different way, whereby the 'fields' are actually forms, and the data entered simply gets appended to the post? If so any chance you doing one where the field data is stored in the db seperately? saves me the fuss and I could make a donation :D )
As I said "I suggest creating another table that holds the user's ID, the question ID and their answer.
If you know how to use 'LEFT JOIN' then you do not need to make a field for "thread ID" but since you do not know that much you should add "thread ID"."
When an user edits their post call the table where the thread ID matches the thread ID in the table and where the user ID of the person browsing matches the user ID in the table.
Then you fill in the form question with the data received from said table.
New table:
my_thread_fields
Fields:
questionid (key)
ThreadID = (INT 20)
question (text)
status (tinyint 1) (to "show" or "hide" the question.)
New table:
my_thread_fields_answers
Fields:
answerid (key)
UserID (INT 40)
ThreadID = (INT 20)
questionid (INT 10)
Razasharp
06-10-2008, 12:57 AM
Thanks Andrew - I will give it a go and get back to the thread when I get stuck.
Cheers,
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.