user1130272
user1130272

Reputation:

Storing names in database

I recently stared to build a small social network, and im a bit lost and confused about storing the names.

So the point is that, this network will be opend for 4 different countries, Hungary, Russia, French, and America.

The bad part is, if i would like to store the names as first name, last name in the database, that would not be a good idea, because, for example, In Hungary the names are switched, for example, if an Amirecian Citizen signs up as Scott Summers, Scott is the first nameand Summers is the last but for example in Hungarian its totally different, The first name is the last name, and last name is the first, So if Scott where Hungarian, his name would be like this: Summers Scott.

My experience in my country (Hungary) people where really upset when they had their name switched when they signed up for example on facebook, so i would like to avoid that.

I was thinking to give a full name field in the table, but thats not a good idea either (in my opinion).

so i would like to ask a more experienced developers opinion if possible, thank you

Upvotes: 4

Views: 936

Answers (2)

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239646

If every area you work in has a convention that everyone has a family name, one or more given names, and prefers those names to be formatted in a particular format, and you need to process individual parts of the name, then store those facts:

Family Name, Given Name, Other Names and Preferred Name Format. I'd also recommend you let them input a Preferred Name.

Where you'll usually use Preferred Name to address them, and you'll use Preferred Name Format to control assembling Family Name, Given Name and Other Names into a format that is acceptable to them in their culture.

Designing the UI to allow them to input these without error is left as an exercise for the reader :-)

Upvotes: 5

Argeman
Argeman

Reputation: 1353

You can create a view for the table containing the names, and store a flag in the table itself. You can than retrieve the full name from SQL. For example:

SELECT 
    IF(nametable.last_name_first,
        CONCAT(nametable.last_name,' ',nametable.first_name),
        CONCAT(nametable.first_name,' ',nametable.last_name)) AS fullname 
    FROM nametable;

Upvotes: 0

Related Questions