This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's Calculator Programming subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. General Coding and Design => Calculator Programming
Author Message
Demon


Advanced Member


Joined: 17 Jun 2006
Posts: 369

Posted: 23 Jul 2007 05:55:59 pm    Post subject:

I got the following tables right now -- Categories, Forums, Subforums, Topics and Posts.
I'm stuck on the Topics table because a topic could either be in a forum or a subforum.
Do I need one or two cells for forum/subforum?


Code:
function createUserTable() {
   global $usernameMaxLength, $emailMaxLength, $nameMaxLength;
   $query =
  "CREATE TABLE users(
     id INT NOT NULL AUTO_INCREMENT,
     username VARCHAR(".$usernameMaxLength.") NOT NULL,
     password VARCHAR(32) NOT NULL,
     email VARCHAR(".$emailMaxLength.") NOT NULL,
     firstname VARCHAR(".$nameMaxLength.") NOT NULL,
     lastname VARCHAR(".$nameMaxLength.") NOT NULL,
     avatar VARCHAR(30) NOT NULL,
     website VARCHAR(128) NOT NULL,
     signature TEXT NULL,
     powerlevel TINYINT NOT NULL DEFAULT '1',
     PRIMARY KEY(id)
  ) ENGINE=INNODB";
   return mysql_query($query);
}
function createChatTable() {
   global $usernameMaxLength;
   $query =
  "CREATE TABLE chat(
     id INT NOT NULL AUTO_INCREMENT,
     userid INT NOT NULL,
     date DATETIME NOT NULL,
     text TEXT NULL,
     PRIMARY KEY(id)
  ) ENGINE=INNODB";
   return mysql_query($query);
}
function createPMTable() {
   $query =
  "CREATE TABLE pms(
     id INT NOT NULL AUTO_INCREMENT,
     from INT NOT NULL,
     to INT NOT NULL,
     subject VARCHAR(255) NOT NULL,
     date DATETIME NOT NULL,
     text TEXT NULL,
     PRIMARY KEY(id)
  ) ENGINE=INNODB";
  return mysql_query($query);
}
function createCategoriesTable() {
   $query =
  "CREATE TABLE categories(
     id INT NOT NULL AUTO_INCREMENT,
     title VARCHAR(128) NOT NULL,
     description VARCHAR(128) NOT NULL,
     PRIMARY KEY(id)
  ) ENGINE=INNODB";
  return mysql_query($query);
}
function createForumsTable() {
   $query =
  "CREATE TABLE forums(
     id INT NOT NULL AUTO_INCREMENT,
     category INT NOT NULL,
     title VARCHAR(255) NOT NULL,
     comment TEXT NULL,
     leader INT NOT NULL,
     permissions INT NOT NULL
     PRIMARY KEY(id)
  ) ENGINE=INNODB";
   return mysql_query($query);
}
function createSubforumsTable() {
   $query =
  "CREATE TABLE forums(
     id INT NOT NULL AUTO_INCREMENT,
     forum INT NOT NULL,
     title VARCHAR(255) NOT NULL,
     comment TEXT NULL,
     leader INT NOT NULL,
     permissions INT NOT NULL
     PRIMARY KEY(id)
  ) ENGINE=INNODB";
   return mysql_query($query);
}
function createTopicsTable() {
   $query =
  "CREATE TABLE topics(
     id INT NOT NULL AUTO_INCREMENT,
     forum INT NOT NULL,
     subforum INT NOT NULL,
     title VARCHAR(128) NOT NULL,
     comment VARCHAR(128) NOT NULL,
     creator INT NOT NULL,
     PRIMARY KEY(id)
  ) ENGINE=INNODB";
   return mysql_query($query);
}
function createPostsTable() {
   $query =
  "CREATE TABLE posts(
     id INT NOT NULL AUTO_INCREMENT,
     topic INT NOT NULL,
     poster INT NOT NULL,
     text TEXT NULL,
     PRIMARY KEY(id)
  ) ENGINE=INNODB";
   return mysql_query($query);
}



EDIT: Never mind, I just decided not to include subforums unless it's a bad idea to have forums without subforums or something.


Last edited by Guest on 23 Jul 2007 06:38:14 pm; edited 1 time in total
Back to top
Arcane Wizard
`semi-hippie`


Super Elite (Last Title)


Joined: 02 Jun 2003
Posts: 8993

Posted: 24 Jul 2007 04:54:31 am    Post subject:

Subforums are forums. They can both have categories, but a subforum has a parent forum, which means a column with the id of the forum it's a child to.

get rid of the subforum table, add category and parentid to forum table. parent id = 0 for root level forums.

Then topic always has a foreign key forum id.

http://dev.mysql.com/doc/refman/5.0/en/inn...onstraints.html


Last edited by Guest on 24 Jul 2007 04:55:27 am; edited 1 time in total
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement