forum help
Moderator: General Moderators
forum help
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
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 ................*/Weirdan wrote:I'd suggest to arrange your tables as follows:
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 wrote:thanks but still the problem with the creating a table number 1 more than the previous post or does that do it automatically
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:
try to implement this using your db scheme 
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
}