Jump to content

New table created from variable. Can it be done?


Potatis

Recommended Posts

Hi all,

 

Is it possible to create a table in a mysql database using a variable that originated from a form? I've searched the net for some info on this, but have had no success.

 

Basically I want an admin to be able to set up a weekly round of football, and have a new table created for that round, based on teams set up each week using a form. The admin would enter the round number, and that would be the name of the new table. The teams listed in the form would simply be posted in the table after it is created with a game ID. So far, I only know how to create a table by running a sql query, but the admin won't know how to do that, I'd rather if it could be done using a form.

 

Thanks for any help.

This could be done, you'd just dynamically create the SQL query and run it based on the form input:

CREATE TABLE `$_POST[table_name]` ...

But this is NOT recommended!

I'd highly suggest you do some research on database design, you need to be able to store this data and recall it using a set database schema, you shouldn't be dynamically creating tables!

i often simply give a record multiple id's

eg, if i was to have a message sectionin my site, then instead of habing a message table for every user, then i create the uniqu messsage id, the user-Id of who its to, and then the chain id, which is like reply... eg chain id "2" means its a reply to id "1".

 

Hope this helps

Thanks PC Nerd, I hadn't thought about multiple ids. I'll have a think about how I can apply it to my game ids so I don't need to set up new tables.

 

The alternative I am trying to avoid is having to set up a pre-made database with all the rounds already set up in tables. I'm sure It'll all become clearer when I study it some more. It's becoming obvious that I need to learn more about working with databases, beyond typical data retrieval.  :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.