0

I have a table named project which contain 4 columns(ID,NAME,FEATURE,DOWNLOAD).For each entry in the 'project' I need to create a new table in the same database with the name pro1, pro2, pro3 and so on. In my web UI, I have to give a button for creating a new table for each new project, then what should be the sql query for that? I use php. The user should be able to add new projects in the 'project' table and then on a button click or automatically a new table is to be created dynamically with the naming convention I have shown above . I cannot add all the features to the 'project' table due to some other reasons, that is why a new table is created for each project..Thanks in advance

1
  • 1
    That's a really bad idea. A much better alternative would be to add another key column "projectId" to each table you would duplicate that way. Commented Nov 30, 2012 at 6:19

1 Answer 1

1

On button click you could do the following:

  • Get the number of rows currently present in project, say $nor
  • Increment $nor by 1
  • Run the CREATE TABLE query using "CREATE TABLE IF NOT EXISTS pro".$nor
Sign up to request clarification or add additional context in comments.

2 Comments

how to get number of rows currently present? your idea seems to work
$nor = mysql_num_rows(mysql_query("SELECT ID FROM project")); I'm assuming you're using mysql_* functions. Be advised that they are going to be deprecated soon. You better switch to PDO or MySQLi if that is the case

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.