Dynamic Table Name

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
tonyacunar
Forum Newbie
Posts: 8
Joined: Thu May 11, 2006 11:03 am

Dynamic Table Name

Post 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!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Sure you need a new table for each new user?
Might be but usually it's wrong.
tonyacunar
Forum Newbie
Posts: 8
Joined: Thu May 11, 2006 11:03 am

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I still see no need for more than one table.
table `scores`: game_id, user_id, score
tonyacunar
Forum Newbie
Posts: 8
Joined: Thu May 11, 2006 11:03 am

Post 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
Post Reply