1

I need to make a column that has an auto incrementing integer. (it can't be the following...)...

$query = "CREATE TABLE $username (messages TEXT, id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id))";

Let me give you a discription of what I'm trying to do...

This code is for the create an account page on my the website I'm making. The site a messaging system (network). The $username variable in the query is to make a table for that user (it is named after the users username). The column for the messages TEXT is for the persons messages. The column id is so when the user tries to delete a message it will be able to delete the message with corresponding id. This means that the id column for each message must be different for each message.

I hope you understand,

Thank you in advance

www139
  • 77
  • 9
  • 1
    Making a table for each username is just wrong and a bad usage for MySQL, what you should do is an associative table that you can link messages to a given user. For example on the registration, you create the user on the table users with the fields id, username, password and on a secondary table called messages with the following fields id, user_id, message you will be storing the users message and then you can easily link the messages back to a given users by selecting its id for example `SELECT u.username, m.message FROM messages m LEFT JOIN users u ON u.id = m.user_id` – Prix Feb 15 '14 at 01:38
  • I'm just starting mysql, so I don't know very much. What is a good resource? – www139 Feb 15 '14 at 01:40
  • 1
    Here is a good place to start and remember to always search before making posts as they may have been answered already [Any good relational database tutorials?](http://stackoverflow.com/questions/2226558/any-good-relational-database-tutorials) and here is another example [Understanding JOINs in MySQL and Other Relational Databases](http://www.sitepoint.com/understanding-sql-joins-mysql-database/) – Prix Feb 15 '14 at 01:41
  • how do you make a secondary table? – www139 Feb 15 '14 at 01:41
  • mysql only supports auto_inc columnets for tables' primary keys, and there can only be **ONE** auto_inc column per table. – Marc B Feb 15 '14 at 01:41
  • Thank you for your help I will read the comments you have left :), :D – www139 Feb 15 '14 at 01:43
  • @user3234267 [I will suggest you to install the Windows version of MySQL on your computer and use it to play with the queries and tables before you start to actually working with it on PHP u will be able to learn a lot of it and also see it working first hand to understand what happens.](http://dev.mysql.com/downloads/mysql/) – Prix Feb 15 '14 at 01:44
  • I'm afraid I don't have a windows computer at the moment, (I'm only 13yrs.) – www139 Feb 15 '14 at 01:48
  • @user3234267 there is a version of MySQL to almost any type of operational system you can click on my previous comment link and it will lead u to the download page where you can select what type of computer you have. – Prix Feb 15 '14 at 01:50

0 Answers0