MyBB Community Forums

Full Version: Getting info from newthread
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hey Guys,

I need to add a new field to the newthread template(no problem), but how do I get the information from it?
Please help me out!

Thanks!
Aniruddh
First, you take input from user and store it (don't forget to escape it) in the threads table in the field which you have created.

Then you can either call $thread variable and display using it (not sure if it may work) or run a query like this:

$query = $db->query("SELECT your_field_name FROM ".TABLE_PREFIX."threads");

//Fetch it

while($field = $db->fetch_array($query))
{
$list = $field['your_field_name'];
}

Then you can run suitable hooks on the pages you want to display and show it by evaluating your custom template. For above example, our variable which was fetching the final values was $list, so in templates you need to add {$list}.

But make sure to run hooks at right place otherwise it won't display any data.
Can you elaborate a bit more? I am kinda new to PHP and MyBB plugins.
What part you're stuck at?
In my current code, I create a new template for the field. Actually then, how do I include it in the newthread field? Will it automatically be entered in the database, or I need to create a field via the plugin?
No, templates don't work like that. It would just provide you with the field, but taking the input from user and storing into the database has to be done by plugin.
Ok, so how do I store it?
Is it just like PHP using mysql_query()?
Many things in MyBB are different...
MyBB uses $db object instead of manually adding mysql_query and such objects everywhere. Just define $db in globals and you can use it instead of mysql_query.
so, like $db(query here)?
No, you'd use something like this:

function someFunction()
{
global $db;

$db->query("SELECT your_field_name FROM ".TABLE_PREFIX."threads");

// rest of code
}

See this: http://docs.mybb.com/Database_Constants.html
Pages: 1 2