Creating a table on Install
#1
Sorry for such a basic question, but i am developing a very niche plugin with my minimal knowledge. I get many problems, but I usually sort them out after awhile. But for some reason, i just can't get my plugin to create a database table.

function turnorder_install()
{
	global $db;
    $charset = $db->build_create_table_collation();
    if(!$db->table_exists("turnorder")){
		/*
		$a=1;
		$columnNumber="";
		while($a<=10){
			$columnNumber .= "turn".$a." VARCHAR(30),
			";
			$a++;
		}
		rtrim($columnNumber, ",");

		$createTable = "CREATE TABLE mybb_turnorder (
		id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
		thread SMALLINT(5) NOT NULL,
		lastPosition TINYINT(2) DEFAULT 1 UNSIGNED,
		".$columnNumber." )";
		*/
		$createTable = "CREATE TABLE mybb_turnorder (
		id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
		thread SMALLINT(5) NOT NULL,
		lastPosition TINYINT(2) DEFAULT 1 UNSIGNED,
		turn1 VARCHAR(30),
		turn2 VARCHAR(30),
		turn3 VARCHAR(30),
		turn4 VARCHAR(30),
		turn5 VARCHAR(30),
		turn6 VARCHAR(30),
		turn7 VARCHAR(30),
		turn8 VARCHAR(30),
		turn9 VARCHAR(30),
		turn10 VARCHAR(30))";
		$tableOrder = mysqli_query($db, $createTable);
	}
}


I am thankful for any insight on this. Thank you in Advance.

P.S. the commented out was my original idea for future convenience, if I decide to change the turn field amount.
Reply


Messages In This Thread
Creating a table on Install - by Algraud - 2016-11-18, 08:59 PM
RE: Creating a table on Install - by VirtualFrost - 2016-11-19, 11:04 AM
RE: Creating a table on Install - by dragonexpert - 2016-11-19, 02:23 PM
RE: Creating a table on Install - by Algraud - 2016-11-21, 05:27 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)