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!

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)