Akenatehm Posted November 29, 2008 Share Posted November 29, 2008 Hey Guys, What I need to do is create a table that has a name auto incrementing. For example: Creates Table "table1" Creates Table "table2" Creates Table "table3" The script is querying the database to see what the next number is OR Another Script Somewhere Else Tries to Create "table2" It finds out that it already exists. and then it keeps going up the numbers. "table4" etc. till it finds one that isn't taken up. Any help will be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/134719-solved-creating-new-mysql-tables-with-an-auto-incrementing-name/ Share on other sites More sharing options...
trq Posted November 29, 2008 Share Posted November 29, 2008 This smells of poor design, why exactly would you be needing to do this? Quote Link to comment https://forums.phpfreaks.com/topic/134719-solved-creating-new-mysql-tables-with-an-auto-incrementing-name/#findComment-701497 Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 We are creating an instant messaging client. This would be creating the chat rooms, where all the conversations are stored. Messages and Senders will be listed in here. Here is how I mean: chatroom1 chatroom2 chatroom3 to chatroom40 etc etc Quote Link to comment https://forums.phpfreaks.com/topic/134719-solved-creating-new-mysql-tables-with-an-auto-incrementing-name/#findComment-701501 Share on other sites More sharing options...
trq Posted November 29, 2008 Share Posted November 29, 2008 You would still be better off using one table. You'd just create a field to store the chat room number in. Quote Link to comment https://forums.phpfreaks.com/topic/134719-solved-creating-new-mysql-tables-with-an-auto-incrementing-name/#findComment-701503 Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 But wouldn't that create huge server load if there are say.... 100 conversations at once all connecting to the same database? Quote Link to comment https://forums.phpfreaks.com/topic/134719-solved-creating-new-mysql-tables-with-an-auto-incrementing-name/#findComment-701507 Share on other sites More sharing options...
trq Posted November 29, 2008 Share Posted November 29, 2008 But wouldn't that create huge server load if there are say.... 100 conversations at once all connecting to the same database? All tables are going to be within the same database on the same server anyway. Quote Link to comment https://forums.phpfreaks.com/topic/134719-solved-creating-new-mysql-tables-with-an-auto-incrementing-name/#findComment-701510 Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 Ok. So how do you suggest I lay the table out, what field types? Going to have following fields: chatid, username, date Quote Link to comment https://forums.phpfreaks.com/topic/134719-solved-creating-new-mysql-tables-with-an-auto-incrementing-name/#findComment-701513 Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/134719-solved-creating-new-mysql-tables-with-an-auto-incrementing-name/#findComment-701530 Share on other sites More sharing options...
corbin Posted November 29, 2008 Share Posted November 29, 2008 Well, you'll have your users table, then you'll have your chatrooms table, then you'll have your messages table: CREATE TABLE msgs ( user_id INT NOT NULL, --author chatroom_id INT NOT NULL, message_content text ); Edit: Google "database normalization" and you might develop a better approach of how to store data. Quote Link to comment https://forums.phpfreaks.com/topic/134719-solved-creating-new-mysql-tables-with-an-auto-incrementing-name/#findComment-701536 Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/134719-solved-creating-new-mysql-tables-with-an-auto-incrementing-name/#findComment-701544 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.