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 Answer
On button click you could do the following:
- Get the number of rows currently present in
project, say$nor - Increment
$norby 1 - Run the
CREATE TABLEquery using"CREATE TABLE IF NOT EXISTS pro".$nor
2 Comments
ess.crazy
how to get number of rows currently present? your idea seems to work
asprin
$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