batstanggt Posted July 30, 2011 Share Posted July 30, 2011 hey guys i have a website im working on and i would like to have 5 separate tables be created in my database for each user who registers. Is it possible to use a variable taken from the register form to use in the table name? Ie... CREATE TABLE ($id)table_name ( column_name1 data_type, column_name2 data_type, column_name3 data_type, .... ) $id is obviously the variable. I dont know if that is te correct syntax but if someone could tell me how to do this that would be great. So basically the name of the table created from that would be for example 1table_name, 2table_name, 3table_name etc.... Then would I just put 5 create table statements in my registration.php page one right after another so that the tables are created as the registration is completed? I have only ever used phpmyadmin so far to create tables so im not sure about using code to create a table let alone 5 at one time hahaha. Thanks guys. -SB Quote Link to comment https://forums.phpfreaks.com/topic/243294-create-tables-on-register/ Share on other sites More sharing options...
Pikachu2000 Posted July 30, 2011 Share Posted July 30, 2011 No, you really do not want to do that; there is absolutely no reason to add tables to a database just because a user registers, and you'll be creating a nightmare for yourself in the future. You need to use a normalized database structure, not attempt to force a relational database to mimic a spreadsheet. Quote Link to comment https://forums.phpfreaks.com/topic/243294-create-tables-on-register/#findComment-1249489 Share on other sites More sharing options...
batstanggt Posted July 30, 2011 Author Share Posted July 30, 2011 Ahhh I see. Thanks pikachu i think you are right though something did seem awkward about trying to use a relational database structure (forced if you will). Now I did follow your link but would you mind explaining ..."You need to use a normalized database structure, not attempt to force a relational database to mimic a spreadsheet". And I'm not really sure how that would create a nightmare for myself would you mind also explaining that? Im not challenging your opinion im just curious to learnin why. -SB Quote Link to comment https://forums.phpfreaks.com/topic/243294-create-tables-on-register/#findComment-1249512 Share on other sites More sharing options...
Pikachu2000 Posted July 30, 2011 Share Posted July 30, 2011 If you have even a small amount of users register, let's say 5000, you now have 25,000 tables in the DB. What happens when you need to select a common piece of data, like the date the users joined perhaps, from all the tables and compare it? Quote Link to comment https://forums.phpfreaks.com/topic/243294-create-tables-on-register/#findComment-1249528 Share on other sites More sharing options...
batstanggt Posted July 31, 2011 Author Share Posted July 31, 2011 lets just say i did want to dig my own grave and try this how would i do it what would the code be? -SB Quote Link to comment https://forums.phpfreaks.com/topic/243294-create-tables-on-register/#findComment-1249654 Share on other sites More sharing options...
trq Posted July 31, 2011 Share Posted July 31, 2011 You really DO NOT want to do this. Quote Link to comment https://forums.phpfreaks.com/topic/243294-create-tables-on-register/#findComment-1249657 Share on other sites More sharing options...
batstanggt Posted July 31, 2011 Author Share Posted July 31, 2011 LMAO but what if each user is the only one updating this database does that make any difference. I really really do appreciate your advice like i say dont take that as a challenge of ur solution but more so curious if the fact that i wont be modifying anything has any bearing on the situation what so ever. Or just bad idea no matter what and why...please. Im of the mind that if you fish for a man he eats for a week, if you teach him to fish he eats for life hahah. Thanks guys. -SB Quote Link to comment https://forums.phpfreaks.com/topic/243294-create-tables-on-register/#findComment-1249671 Share on other sites More sharing options...
trq Posted July 31, 2011 Share Posted July 31, 2011 I think it's been outlined already by Pik. If you need to query any data across users you'll be *uc*ed. It's just a terrible design and has only downsides. Quote Link to comment https://forums.phpfreaks.com/topic/243294-create-tables-on-register/#findComment-1249674 Share on other sites More sharing options...
fenway Posted July 31, 2011 Share Posted July 31, 2011 There is ZERO benefit to have N sets of tables for N users. You're building partitioning at a very low level. Quote Link to comment https://forums.phpfreaks.com/topic/243294-create-tables-on-register/#findComment-1249785 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.