dougang5993
2013-12-16 19:40
浏览 18
已采纳

MySQL PHP从数据库中选择和编辑值[关闭]

I have a database containing a list of characters for a game. The user is required to search for 5 characters and assign a position to each selected character. This list of 5 with positions needs to be saved so that it can be retrieved later.

In VB.NET I simply created a file that contained the selected 5 with their assigned positions and read the data from this.

Now I am trying to create a web-based version I am struggling as to how I should save the data. The large database is in a MySQL table. I am guessing that it wouldn't make sense to create a new table for each user and have individual rows for their selected characters? My thinking is to have a single table called 'users' then store the selected characters in a column with their position e.g. "player1:pos4,player56:pos302,player322:pos392' etc. then I can split the values later.

Does anyone have any more efficient ideas on how to approach this? I am very new to all this thanks!

图片转代码服务由CSDN问答提供 功能建议

我有一个包含游戏角色列表的数据库。 用户需要搜索5个字符并为每个选定的字符分配位置。 需要保存5个带位置的列表,以便以后检索。

在VB.NET中,我只是创建了一个文件,其中包含所选的5及其指定位置并读取 来自此的数据。

现在我正在尝试创建一个基于Web的版本,我正在努力解决如何保存数据的问题。 大型数据库位于MySQL表中。 我猜测为每个用户创建一个新表并为其所选字符分别设置行是没有意义的吗? 我的想法是让一个名为“用户”的表然后将所选字符存储在一个列中,例如它们的位置。 “player1:pos4,player56:pos302,player322:pos392'等,然后我可以稍后拆分这些值。

有没有人对如何解决这个问题有任何更有效的想法?我非常 所有这一切的新人谢谢!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanbushi1479 2013-12-16 20:23
    已采纳

    I would create 3 basic tables: users, characters, positions, and 1 lookup table: usercharpos with 3 columns: user_id, char_id, pos_id. Each user, character and position should have a unique id as primary key. Then, in the usercharpos lookup table I would associate a user with the 5 chosen characters and the position of each one. For example, we have a user with id = 5, that chose some characters with ids = 1,2,3,4,5 and chose some positions for them with ids = 2,3,6,7,8. The usercharpos would become:

    user_id   char_id   pos_id
       5         1        2
       5         2        3
       5         3        6
       5         4        7
       5         5        8
    

    That way, you keep your database normalized and each entity has its own table without multiple values in a field.

    打赏 评论

相关推荐 更多相似问题