Page 1 of 1

forum help

Posted: Thu Dec 18, 2003 2:00 pm
by AliJay
i have a problem with this forum i am making. As i don't have alot of databases i am making each new topic contents in a different table with 2 fields contents and name. then there is a main database of all the topics. My site when it sees a topic it links it to index2.php?page=topic&topic=$ID how can i create a table with 1 more in value than the previous table created e.g. if 1 has been created how can i make it automatically create 2

Posted: Thu Dec 18, 2003 2:02 pm
by Weirdan
you can use [php_man]mysql_list_tables[/php_man] although it's a bad design decision IMO.

Posted: Thu Dec 18, 2003 2:05 pm
by AliJay
how could i improve my design

Posted: Thu Dec 18, 2003 2:32 pm
by Weirdan
I'd suggest to arrange your tables as follows:

Code: Select all

create table threads(
     id int not null auto_increment, 
     subject char(128),
     starter int not null references users id match full, 
     lastreply datetime, 
     ... , 
     primary key(id)
 );
 create table posts(
     id int not null auto_increment, 
     contents text, 
     poster int not null references users id match full, 
     dateinsert datetime references threads lastreply on update cascade, 
     .... , 
     primary key(id)
 );
 create table users(
     id int not null auto_increment, 
     login char(32), 
     password char(32), 
     email char(128), 
     .... , 
     primary key(id)
);
/* ........... some other tables ................*/

Posted: Fri Dec 19, 2003 11:07 am
by AliJay
thanks but still the problem with the creating a table number 1 more than the previous post or does that do it automatically

Posted: Fri Dec 19, 2003 11:17 am
by Crashin
Weirdan wrote:I'd suggest to arrange your tables as follows:
AliJay wrote:thanks but still the problem with the creating a table number 1 more than the previous post or does that do it automatically
If I understand Weirdan's thoughts on this, the auto increment in the tables will take care of your issue. Using the above table scheme, you won't need to create a new table for every post.

Posted: Fri Dec 19, 2003 11:23 am
by AliJay
oh ok thanks lots

Posted: Fri Dec 19, 2003 1:13 pm
by AliJay
one more question why is mysql_list_tables a bad design thing

Posted: Fri Dec 19, 2003 1:38 pm
by Weirdan
not mysql_list_tables by itself but the db scheme which requires use of mysql_list_tables in order to retrieve the list of topics. It's against the spirit of relational databases. This design will bring more headache.
Suppose you want to find all posts of given user, regardless in which topic they're posted... using the table layout suggested by me:

Code: Select all

$result=mysql_query("select contents,subject, login from posts,users where users.id=posts.poster and login='".$_GET['login_to_search_for']."'");
while($row=mysql_fetch_row($result)){
  // display the post
}
try to implement this using your db scheme ;)

Posted: Sun Dec 21, 2003 10:25 am
by AliJay
oh ok