Jump to the post that solved this thread.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Solved: 4 Years, 1 Month ago Need help with database
#1
Solved: 4 Years, 1 Month ago
Hello, I currently have a table named mybb_servers with a category of status inside it which just holds off.

I want to write a script that when its run, changes whats held to ono.

So far I have:

// Require the Global file

define('IN_MYBB', 1);
require_once "./global.php";

// Write to DB

$db->write_query("INSERT INTO ".TABLE_PREFIX."servers (status) VALUES
(ono);

I have not tested this yet in case it messes anything up, could someone please just let me know if this is the correct method on doing it?

Thanks in advance.
Reply
#2
Solved: 4 Years, 1 Month ago
@Nineteh, you didn't close quote and bracket:

$db->write_query("INSERT INTO ".TABLE_PREFIX."servers (status) VALUES (ono)");

the correct query you can use is:

$db->insert_query("servers", array("status" => "ono"));
[Image: ZbrcFs]
Reply
#3
Solved: 4 Years, 1 Month ago
Chack you're a genius! I actually saw this in the methods but didn't think to use it. Thankyou buddy!
Reply
#4
Solved: 4 Years, 1 Month ago
Hello, I required a great bit of code from a fellow member which works great:

// Require the Global file

define('IN_MYBB', 1);
require_once "./global.php";

// Write to DB

if ($mybb->user['usergroup'] == 10 || $mybb->user['usergroup'] == 4) {
	
	$db->insert_query("servers", array("status" => "ono"));
}

?>

The only problem I am having is that instead of overwriting the current 'off' thats stored, it creates a new one. Is there are a way to delete everything inside the category 'status' before it creates a new one?

Thanks in advance.

EDIT: Would this work?

$db->delete_query('servers', '*', "status = 'off'");
Or maybe this?
$db->drop_column("servers", "status");
Reply
#5
Solved: 4 Years, 1 Month ago
@Ninethe you can use update method:

    $query = $db->simple_select("servers", "*");
    if($db->num_rows($query) > 0) {
        $db->update_query("servers", array("status" => "ono"));
    } else {
        $db->insert_query("servers", array("status" => "ono"));
    }

WARNING!
I don't know your database, so I don't know if this code will work
[Image: ZbrcFs]
Reply
Jump to the post that solved this thread.


Forum Jump:


Users browsing this thread: 1 Guest(s)