25.11.2015, 19:38
Like I said, the name should only appear once in the database. While it is technically possible to set up a foreign key relation with a text type field, it is discouraged to do so because string comparison is obviously much slower than integer comparison. Especially for varchar fields where length is not fixed.
If you have it properly set up you should have a column "ownedBy" or "ownerId" or something like that in the house table. That column only contains numeric ids, like 5 or 42. This id corresponds to ONE player. You can go and look this up in the player table to find out who it is.
Now, there's obviously also queries that do this. You can do this with two separate queries, or with a join. That depends on the situation.
That will give all columns from the house table (house.*), plus an extra column which contains the player's name from the player table (player.name).
If you have it properly set up you should have a column "ownedBy" or "ownerId" or something like that in the house table. That column only contains numeric ids, like 5 or 42. This id corresponds to ONE player. You can go and look this up in the player table to find out who it is.
Now, there's obviously also queries that do this. You can do this with two separate queries, or with a join. That depends on the situation.
PHP Code:
SELECT house.*, player.name
FROM house
JOIN player
ON house.ownerId = player.id