Page 1 of 1

php function to create a table is it possible?

Posted: Tue Jun 24, 2003 2:30 pm
by mikesheridan5
im stuck with a logic blank mind... I am creating a golf tournament type app using php and initially the admin will be able to create a season and when the admin creates a season it will grab all the players in the player table and will put the players into a season table for that particualr season. now my problem is trying to make a efficient database deisgn. my initial thought was to create a function that creates a table for that particualr season and throws whatever palyers there are in the players table into that season. am i losing you yet 8O is that a bad idea? or am i heading in the right direction to accomplish this task? any help would be greatly appreciated

Posted: Tue Jun 24, 2003 2:34 pm
by nielsene
Yes its possible. Just pass the "CREATE TABLE..." query to the database as you pass any other query.

Whether its a good idea or not can only be determined with more infomration. For instance, why you need a new table, instead of adding a season column to an existing table?

(Using one table per season violates the "Information Principle" as it hides "meaning" from the database system, by embeding it in table names.)

Posted: Tue Jun 24, 2003 2:44 pm
by mikesheridan5
well ok here let me try to sum it up so i can do this right the first time =0

ok the admin will be able to add/delete players and add a season

i figure id have 2 tables to start with one being the players table with player info and another table Season, i figured i would do it that way so when the admin creates a new season it would make a new table with season info and adding all the players in the player table, reason behind this is when the admin creates a new season the old season will still keep the information regarding that season (player scored and such) while the new season will hold the new season information. (in case there are new players/ or players leave). Now doing it that way i would be able to list the seasons with all the info from that season. but you are right about the information principle.

so what you are suggesting is that when the admin creates a new season that uses a season column that defines that season but how would i add all the players for that season to that table. im confused now =0

thanks, for the reply

Posted: Tue Jun 24, 2003 2:51 pm
by nielsene
Why not use three tables:

Players

Seasons

Players_in_season

Now adding a season is simply adding a row to the seasons table, and then copying the appropriate players into the the player_in_season table with the new season id?

Posted: Tue Jun 24, 2003 3:00 pm
by mikesheridan5
well i cant argue with that.. that makes alot more sense.. as you can tell im still learning =) Thanks for the help!!!
you saved me a headache