开发者

Add several fields to MySQL Database

I am fairly new to building sites with PHP and MySQL but am trying to achieve the following:

During an online enrollment process, a promoter is able to enroll up to 20 'fighters' for medical testing services. Each fighter's information is stored in SESSION as $_SESSION['FnumAttr'] where num is the number and Attr is the attribute being defined (first name, last name, etc). At the end of 开发者_开发百科the enrollment, I need ALL of the data entered stored in a MySQL DB and eventually sent on elsewhere. A manager can enroll from 1 to 20 fighters at a time and any thing less than 20 will just not have data (null) within its cell.

I am currently building out the DB within MySQL but if I have to enter 20 attributes for 20 different fighters this may take all day (not to mention the "INSERT INTO" call I'll have to make at the end of all this).

Is there a way to create these fields more quickly than going line by line and adding: F4_Firstname, type text, length, allow null, etc..?


This looks like a one-to-many relationship. Instead of having 20 columns create a new table called "fighters" that contains a fighter id, parent_table_id, and the information about the fighter.

When you need the fighter information you join the fighter table with the parent table on parent_table_id.

To load this new table just loop through your original array and issue an insert statement for any entries you find that are not null. If you make the new table's PK a concatenation between fighter_id and parent_table_id then you can use 'num' from your input data directly as fighter_id.


You could use phpMyAdmin

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜