boards now have individual tables.

This commit is contained in:
Savetheinternet 2010-12-02 19:08:29 +11:00
parent f753b709ff
commit 41daaa16b1
3 changed files with 24 additions and 23 deletions

View File

@ -69,9 +69,10 @@
} }
function threadExists($id) { function threadExists($id) {
global $sql; global $sql, $board;
$thread_res = mysql_query(sprintf( $thread_res = mysql_query(sprintf(
"SELECT 1 FROM `posts` WHERE `id` = '%d' AND `thread` IS NULL LIMIT 1", "SELECT 1 FROM `posts_%s` WHERE `id` = '%d' AND `thread` IS NULL LIMIT 1",
mysql_real_escape_string($board['uri']),
$id $id
), $sql) or error(mysql_error($sql)); ), $sql) or error(mysql_error($sql));
@ -84,8 +85,8 @@
global $sql, $board; global $sql, $board;
if($OP) { if($OP) {
mysql_query( mysql_query(
sprintf("INSERT INTO `posts` VALUES ( NULL, '%d', NULL, '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%s', '%d', '%d', '%s', '%d', '%d', '%d', '%s', '%s', '%s', '%s' )", sprintf("INSERT INTO `posts_%s` VALUES ( NULL, NULL, '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%s', '%d', '%d', '%s', '%d', '%d', '%d', '%s', '%s', '%s', '%s' )",
$board['id'], mysql_real_escape_string($board['uri']),
$post['subject'], $post['subject'],
$post['email'], $post['email'],
$post['name'], $post['name'],
@ -108,8 +109,8 @@
return mysql_insert_id($sql); return mysql_insert_id($sql);
} else { } else {
mysql_query( mysql_query(
sprintf("INSERT INTO `posts` VALUES ( NULL, '%d', '%d', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%s', '%d', '%d', '%s', '%d', '%d', '%d', '%s', '%s', '%s', '%s' )", sprintf("INSERT INTO `posts_%s` VALUES ( NULL, '%d', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%s', '%d', '%d', '%s', '%d', '%d', '%d', '%s', '%s', '%s', '%s' )",
$board['id'], mysql_real_escape_string($board['uri']),
$post['thread'], $post['thread'],
$post['subject'], $post['subject'],
$post['email'], $post['email'],
@ -142,8 +143,8 @@
sql_open(); sql_open();
$query = mysql_query(sprintf( $query = mysql_query(sprintf(
"SELECT * FROM `posts` WHERE `thread` IS NULL AND `board` = '%d' ORDER BY `bump` DESC LIMIT %d,%d", "SELECT * FROM `posts_%s` WHERE `thread` IS NULL ORDER BY `bump` DESC LIMIT %d,%d",
$board['id'], mysql_real_escape_string($board['uri']),
$offset, $offset,
THREADS_PER_PAGE THREADS_PER_PAGE
), $sql) or error(mysql_error($sql)); ), $sql) or error(mysql_error($sql));
@ -153,15 +154,15 @@
$thread = new Thread($th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['body'], $th['time'], $th['thumb'], $th['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename']); $thread = new Thread($th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['body'], $th['time'], $th['thumb'], $th['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename']);
$newposts = mysql_query(sprintf( $newposts = mysql_query(sprintf(
"SELECT `id`, `subject`, `email`, `name`, `trip`, `body`, `time`, `thumb`, `thumbwidth`, `thumbheight`, `file`, `filewidth`, `fileheight`, `filesize`, `filename` FROM `posts` WHERE `board` = '%d' AND `thread` = '%s' ORDER BY `time` DESC LIMIT %d", "SELECT `id`, `subject`, `email`, `name`, `trip`, `body`, `time`, `thumb`, `thumbwidth`, `thumbheight`, `file`, `filewidth`, `fileheight`, `filesize`, `filename` FROM `posts_%s` WHERE `thread` = '%s' ORDER BY `time` DESC LIMIT %d",
$board['id'], mysql_real_escape_string($board['uri']),
$th['id'], $th['id'],
THREADS_PREVIEW THREADS_PREVIEW
), $sql) or error(mysql_error($sql)); ), $sql) or error(mysql_error($sql));
if(mysql_num_rows($newposts) == THREADS_PREVIEW) { if(mysql_num_rows($newposts) == THREADS_PREVIEW) {
$count_query = mysql_query(sprintf( $count_query = mysql_query(sprintf(
"SELECT COUNT(`id`) as `num` FROM `posts` WHERE `board` = '%d' AND `thread` = '%s'", "SELECT COUNT(`id`) as `num` FROM `posts_%s` WHERE `thread` = '%s'",
$board['id'], mysql_real_escape_string($board['uri']),
$th['id'] $th['id']
), $sql) or error(mysql_error($sql)); ), $sql) or error(mysql_error($sql));
$count = mysql_fetch_array($count_query); $count = mysql_fetch_array($count_query);
@ -188,8 +189,8 @@
sql_open(); sql_open();
$res = mysql_query(sprintf( $res = mysql_query(sprintf(
"SELECT COUNT(`id`) as `num` FROM `posts` WHERE `board` = '%d' AND `thread` IS NULL", "SELECT COUNT(`id`) as `num` FROM `posts_%s` WHERE `thread` IS NULL",
$board['id'] mysql_real_escape_string($board['uri'])
), $sql) or error(mysql_error($sql)); ), $sql) or error(mysql_error($sql));
$arr = mysql_fetch_array($res); $arr = mysql_fetch_array($res);
$count = floor((THREADS_PER_PAGE + $arr['num'] - 1) / THREADS_PER_PAGE); $count = floor((THREADS_PER_PAGE + $arr['num'] - 1) / THREADS_PER_PAGE);
@ -253,8 +254,8 @@
); );
$result = mysql_query(sprintf( $result = mysql_query(sprintf(
"SELECT `thread`,`id` FROM `posts` WHERE `board` = '%d' AND `id` = '%d' LIMIT 1", "SELECT `thread`,`id` FROM `posts_%s` WHERE `id` = '%d' LIMIT 1",
$board['id'], mysql_real_escape_string($board['uri']),
$cite $cite
), $sql) or error(mysql_error($sql)); ), $sql) or error(mysql_error($sql));
if($post = mysql_fetch_array($result)) { if($post = mysql_fetch_array($result)) {
@ -336,8 +337,8 @@
$id = round($id); $id = round($id);
$query = mysql_query(sprintf( $query = mysql_query(sprintf(
"SELECT `id`,`thread`,`subject`,`name`,`email`,`trip`,`body`,`time`,`thumb`,`thumbwidth`,`thumbheight`,`file`,`filewidth`,`fileheight`,`filesize`,`filename` FROM `posts` WHERE `board` = '%d' AND ((`thread` IS NULL AND `id` = '%s') OR `thread` = '%s') ORDER BY `thread`,`time`", "SELECT `id`,`thread`,`subject`,`name`,`email`,`trip`,`body`,`time`,`thumb`,`thumbwidth`,`thumbheight`,`file`,`filewidth`,`fileheight`,`filesize`,`filename` FROM `posts_%s` WHERE (`thread` IS NULL AND `id` = '%s') OR `thread` = '%s' ORDER BY `thread`,`time`",
$board['id'], mysql_real_escape_string($board['uri']),
$id, $id,
$id $id
), $sql) or error(mysql_error($sql)); ), $sql) or error(mysql_error($sql));

View File

@ -45,12 +45,11 @@ INSERT INTO `boards` (`id`, `uri`, `title`, `subtitle`) VALUES
-- -------------------------------------------------------- -- --------------------------------------------------------
-- --
-- Table structure for table `posts` -- Table structure for table `posts_b`
-- --
CREATE TABLE IF NOT EXISTS `posts` ( CREATE TABLE IF NOT EXISTS `posts_b` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`board` smallint(6) NOT NULL,
`thread` int(11) DEFAULT NULL, `thread` int(11) DEFAULT NULL,
`subject` varchar(40) NOT NULL, `subject` varchar(40) NOT NULL,
`email` varchar(30) NOT NULL, `email` varchar(30) NOT NULL,
@ -74,7 +73,7 @@ CREATE TABLE IF NOT EXISTS `posts` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --
-- Dumping data for table `posts` -- Dumping data for table `posts_b`
-- --
-- -------------------------------------------------------- -- --------------------------------------------------------

View File

@ -296,7 +296,8 @@
if(!$OP) { if(!$OP) {
mysql_query( mysql_query(
sprintf("UPDATE `posts` SET `bump` = '%d' WHERE `id` = '%s' AND `thread` IS NULL", sprintf("UPDATE `posts_%s` SET `bump` = '%d' WHERE `id` = '%s' AND `thread` IS NULL",
mysql_real_escape_string($board['uri']),
time(), time(),
$post['thread'] $post['thread']
), $sql) or error(mysql_error($sql)); ), $sql) or error(mysql_error($sql));