MyBB Community Forums

Full Version: How to update a field in the database?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
What code would i use for a plugin to update a single cell in the mybb_users table?
[Wiki: Database_Methods] (Broken link, head over to docs.mybb.com instead)
update query might help.
so would i put:

global $db->update_query('mybb_users') 

Then how would i pick a certain field to update?
function some_function()
{
    global $db;

    $db->update_query('users', 'column=something, another_column=2', 'uid=1');

}

parameters: ('table name', 'update array', 'conditional')
if i wanted to do an if statement using query would it be:


global $db;

if($db->query('users', 'column=usergoup'='2') == 1;


sorry i am very new to this :/
For if, you could use something like:

function some_function()
{
    global $db;

if($mybb->user['usergroup'] == 2)
{
    $db->update_query('users', 'column=something, another_column=2', 'uid=1');
}
} 
(2011-12-11, 07:23 PM)crazy4cs Wrote: [ -> ]
if($mybb->user['usergroup'] == 2)

is the 2 the gid?

Yeah.
(2011-12-11, 07:40 PM)SmItH197 Wrote: [ -> ]
(2011-12-11, 07:23 PM)crazy4cs Wrote: [ -> ]
if($mybb->user['usergroup'] == 2)

is the 2 the gid?
Yeah.

If you set 4 instead of 2, it'd be admin's group id and likewise.

Pages: 1 2 3