Page 1 of 1

Dynamic Table Name

Posted: Thu Nov 23, 2006 2:45 pm
by tonyacunar
Hi guys, I want to make a table for each user that is created and I want it to be named after the users username. I have the code but I cant seem to get the variable read in. Can you guys help me out? The sql is literally naming the table "$username"

Here is the code:

Code: Select all

$createtable = 'CREATE TABLE IF NOT EXISTS $jack (`key` INT NOT NULL  AUTO_INCREMENT PRIMARY KEY, `username` VARCHAR(40) NOT NULL,
`userbet` INT)';
where $jack is the name of the table that is pulled from a query string(the value from query string is pulled fine.

thanks!

Posted: Thu Nov 23, 2006 3:35 pm
by volka
Sure you need a new table for each new user?
Might be but usually it's wrong.

Posted: Thu Nov 23, 2006 3:53 pm
by tonyacunar
Hi, thanks for your reply, it is actually a table that keeps track of users score in a table they make with the game name. So that is why I have chosen to implement it that way just that I cant make it read the dynamic name
thanks

Posted: Thu Nov 23, 2006 4:37 pm
by volka
I still see no need for more than one table.
table `scores`: game_id, user_id, score

Posted: Thu Nov 23, 2006 5:33 pm
by tonyacunar
hmm, you might be right, actually you are right cuase many tables would make the whole organization suck.. thanks for the suggestion i think that is way much smarter