简体   繁体   English

如何在数据库中配对图像?

[英]How can i pair images in my DB?

I had a hard time giving this question a title, i hope im clear enough. 我很难给这个问题一个标题,我希望我说得足够清楚。 Im using PHP & HTML with a MYSQL Database. 我在MYSQL数据库中使用PHP和HTML。

See I have a member site, where every new member gets a randomly chosen football player as their avatar. 看到我有一个会员站点,每个新成员都会得到一个随机选择的足球运动员作为其化身。 The football player avatar is assigned from a folder named 'avatars'. 足球运动员的头像是从名为“头像”的文件夹中分配的。 Once the user is registered, the avatar is moved to a folder named 'used_avatars'. 注册用户后,头像将移动到名为“ used_avatars”的文件夹中。 Every image is named as the football player, because i want to display the name of the chosen player on the users member page. 每个图像都被称为足球运动员,因为我想在用户成员页面上显示所选运动员的姓名。

Here's the real question: I want to add a flag representing the players nationality on the member site. 真正的问题是:我想在会员网站上添加代表球员国籍的标志。 But I have several Brazilian players and only one Brazilian flag. 但是我有几个巴西球员,只有一面巴西国旗。 How do i pair my 5 players with the one flag. 我如何将我的5个玩家与一个标志配对。 I was thinking of naming the images "brazil-ronaldo", "brazil-carlos" and then in some way in PHP separating the country from the name and match them with a flag and a avatar. 我当时想命名图像“ brazil-ronaldo”,“ brazil-carlos”,然后在PHP中以某种方式将国家与名称分开,并用旗帜和头像进行匹配。 Does this make sense? 这有意义吗? Is there any better way of doing this? 有什么更好的方法吗? I guess I need to create a new table in my database that keeps record of flag and avatar match? 我想我需要在数据库中创建一个新表来保留flag和avatar匹配的记录?

Hope this helps: 希望这可以帮助:

You need a table for players containing field for a nationality id and a table with nationalities with the names for the flags. 您需要一个用于球员的表格,其中包含一个国籍ID的字段,以及一个带有国籍和国旗名称的表格。

This way you can select the player and join the nationality via the id. 这样,您可以选择玩家并通过ID加入国籍。

All you have to do then is save the player id in the user "profile". 然后,您要做的就是将玩家ID保存在用户“个人资料”中。

Instead of assigning a random player avatar for new members, assign a default avatar(cartoon). 代替为新成员分配随机玩家头像,而是分配默认头像(卡通)。

  1. Members/Users table will have a column avatar_id . 成员/用户表将具有一列avatar_id
  2. A table avatars_history (member_id, avatar_id, order) . 一个表avatars_history (member_id, avatar_id, order) where order wil be the sequence in which they were changed. order将是更改顺序。 You can have date too if necessary. 如有必要,您也可以约会。
  3. A table football_players (player_id, country_id, full_name, dob, world_rank, etc) . 一个表格football_players (player_id, country_id, full_name, dob, world_rank, etc)
  4. A table avatars (player_id, avatar_id) where avatar_id is the filename of the picture. 一个表avatars (player_id, avatar_id) ,其中avatar_id是图片的文件名。 Meaning a single player can have multiple pictures. 意味着一个玩家可以拥有多张图片。

And keep all avatars(player pictures with unique names) in a single folder. 并将所有头像(具有唯一名称的玩家头像)保存在一个文件夹中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM