Search code examples
phpsqldatabasecreate-table

Create sql tables dynamically


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


Solution

  • 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