forum help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AliJay
Forum Newbie
Posts: 14
Joined: Mon Nov 24, 2003 11:42 am

forum help

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

you can use [php_man]mysql_list_tables[/php_man] although it's a bad design decision IMO.
AliJay
Forum Newbie
Posts: 14
Joined: Mon Nov 24, 2003 11:42 am

Post by AliJay »

how could i improve my design
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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 ................*/
AliJay
Forum Newbie
Posts: 14
Joined: Mon Nov 24, 2003 11:42 am

Post 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
User avatar
Crashin
Forum Contributor
Posts: 223
Joined: Mon May 06, 2002 3:42 pm
Location: Colorado

Post 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.
AliJay
Forum Newbie
Posts: 14
Joined: Mon Nov 24, 2003 11:42 am

Post by AliJay »

oh ok thanks lots
AliJay
Forum Newbie
Posts: 14
Joined: Mon Nov 24, 2003 11:42 am

Post by AliJay »

one more question why is mysql_list_tables a bad design thing
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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 ;)
AliJay
Forum Newbie
Posts: 14
Joined: Mon Nov 24, 2003 11:42 am

Post by AliJay »

oh ok
Post Reply