3

I have a form in three different languages and store information on a single database. And I have search page that searches for data from database by selecting dropdown menus. But when user searches he gets results only in language he is using. I need to show results from all languages according the users selection. How can I achieve this goal? Any idea and help is appreciated.

More details from comments:

It is a site that trainers register and students search for Trainers. When trainer registers he fills the form and also selects for example the Sector from dropdown menu. And site has 3 version in different languages. And when student searches for a trainer he selects a Sector and I want to show all results related to the selected sector regardless of the language Trainer registered and the user uses.

I have a data table as following

// Table : data
// --------------------------------------------
// username     | name     | sector_id  | lang
// --------------------------------------------
//   jack       |  Jack    | 1      | en
// --------------------------------------------
//   smith      |  Smith   | 1      | fr
// --------------------------------------------

and Sector table as following

// Table : sector
// --------------------------------------------
// sector_id | sector_eng| sector_sp    | sector_fr
// --------------------------------------------
//   1       |  Finance  | Financiar    | la finance
// --------------------------------------------

For example, when user searches for sector Finance I need to get all data both for jack and smith but show la finance for Smith and finance for Jack in result

  • So how is the data stored? Do you use any framework for it? What have you already tried? – julianstark999 May 16 '17 at 10:17
  • @DestinatioN, I have no idea what to do. First, I tried to show data in drop down menu in different languages and store data only in one language. But in search it was problem – Nahid Mirzayev May 16 '17 at 10:27
  • @DestinatioN, data stored in different languages, when user registers he selects from dropdown menu (for example: Sector->IT) and data stored as shown in the form. I don't use any framework – Nahid Mirzayev May 16 '17 at 10:45
  • So if you want to show all results simply not take in account of sector inside your query – julianstark999 May 16 '17 at 10:52
  • @DestinatioN, for example if a user search for finance sector, I want to show results about finance sector in all languages. There are a lot of sectors, I want to show results about the user selects – Nahid Mirzayev May 16 '17 at 11:01
  • Please add some more information on this question. Read [minimal example](https://stackoverflow.com/help/mcve) how to do it. What is your code? Framework etc. – timiTao May 17 '17 at 06:59
  • @timiTao I have given more information on the comments of mi6crazyheart's answer. Maybe reading them can give you idea about problem – Nahid Mirzayev May 17 '17 at 07:10
  • @NahidMirzayev and that is the problem. When someone want to help you, he will need all informations in one place. Please, always update you post with new information. other way - this is poor post. – timiTao May 17 '17 at 07:39
  • @timiTao I am sorry if I acted impolite. Here is more detail: It is a site that trainers register and students search for Trainers. When trainer registers he fills the form and also selects for example the Sector from dropdown menu. And site has 3 version in different languages. And when student searches for a trainer he selects a Sector and I want to show all results related to the selected sector regardless of the language Trainer registered and the user uses. – Nahid Mirzayev May 17 '17 at 10:19
  • @NahidMirzayev i simply updated you post with that information - you can edit your own post, and that is what you should do and in future too, when looking for help. – timiTao May 17 '17 at 10:24

2 Answers2

1

Suppose you are supporting 3 languages(English, Spanish, French) & let's take the example of Finance Sector. Whatever data you are storing for finance sector make 3 version of those data for respective languages & store in your DB.

But, when your user will search on any data - search that on the ENGLISH version of data only. Then, after getting the result(English version) fetch all similar data of other different versions(here it will be Spanish, French) also. Then, according to user's preference show that respective version data.

Hope it'll help you.

Here is a sample table structure according to the use cases which you've shared in your question. it could be different according to your application complexity which I don't know. But, hope it'll give you some basic understanding to move forward.

// Table : sector
// ---------------------------------
// sector_id    | sector_name_eng
// ---------------------------------
//  1           | Finance
// ---------------------------------
//  2           | Statistics
// ---------------------------------
//  3           | Biology
// ---------------------------------


// Table : lang_reference
// ------------------------------
// lang_id      | lang_name
// ------------------------------
//  1           | english
// ------------------------------
//  2           | spanish
// ------------------------------
//  3           | french
//  -----------------------------


// Table : sector_lang_details
// --------------------------------------------
// sector_id    | lang_id   | sector_name
// --------------------------------------------
//   1          |  1        | Finance
// --------------------------------------------
//   1          |  2        | Financiar
// --------------------------------------------
//   1          |  3        | Finance_in_french
// --------------------------------------------
//   2          |  1        | Statistics
// --------------------------------------------
//   2          |  2        | Statistics_in_spanish
// --------------------------------------------
//   2          |  3        | Statistics_in_french
// --------------------------------------------
//   3          |  1        | Biology
// --------------------------------------------
//   3          |  2        | Biology_in_spanish
// --------------------------------------------
//   3          |  3        | Biology_in_french
// ---------------------------------------------------



// Table : trainer_details
// --------------------------------
// trainer_id   | trainer_name
// ---------------------------------
//  1           | Tariner A
// ---------------------------------
//  2           | Tariner B
// ---------------------------------
//  3           | Tariner C
// ---------------------------------


// Table : trainer_teches_sectors
// ---------------------------------
// trainer_id   |   sector_id
// ---------------------------------
//  1           |   1
// ---------------------------------
//  1           |   2
// ---------------------------------
//  2           |   1
// ---------------------------------
//  3           |   3
// ---------------------------------
Suresh
  • 5,687
  • 12
  • 51
  • 80
  • thank you for your answer. Let me explain my form more detailed, maybe you will have more relevant solution. It is a site that trainers register and students search for Trainers. When trainer registers he fills the form and also selects for example the Sector from dropdown menu. And site has 3 version in different languages. And when student searches for a trainer he selects a Sector and I want to show all results related to the selected sector regardless of the language Trainer registered and the user uses. – Nahid Mirzayev May 16 '17 at 11:25
  • Ok. So, what's the problem you are facing to implement this? – Suresh May 16 '17 at 11:39
  • If they are completely different words how can I compare them? For example if user chose Finance from dropdown, how php will get results for financiar (Spanish) also? – Nahid Mirzayev May 16 '17 at 11:55
  • Completely different words!!! can you give one example? I'm bit confused about your requirement. – Suresh May 16 '17 at 11:57
  • For example, there are two trainer in database. One registered with english version and chosen Sector as Finance. And other Trainer registered with spanish version and chosen Sector as Financiar. And a student uses english version for search and choose Finance in Sectors dropdown menu. I need to show results for all trainers in finance (financiar) sector regardless of the language they used when registered (I mean to show both trainers in this example) – Nahid Mirzayev May 16 '17 at 12:02
  • Keep numeric code for each sector. Ex - 10 = finance, 20 = Biology, 30 = Statistics. Then when any trainer register uses the numeric code of respective sector & tag with him. So, if one register with English+Finance & another one is Spanish+Financiar then in both case you should save Sector Code 10 as a flag in DB. Then, when a user will search for Finance with irrespective of any languages... then search for flag 10 in your DB & get all the trainers details. – Suresh May 17 '17 at 04:18
  • mi6crazyheart, thank you very much for your help. Can you give me example of code how can I keep numeric code for each sector, please? – Nahid Mirzayev May 17 '17 at 05:19
  • if you are storing those Sector details in a DB then you can use auto_increment value for Sector Code. So, it'll be like 1,2,3,4,5... so on. Else, you can use your own code just like I've mentioned in above reply(Ex - 10 = finance, 20 = Biology, 30 = Statistics). – Suresh May 17 '17 at 05:23
  • I mean how can I bind numeric values with data and then search by its numeric value? – Nahid Mirzayev May 17 '17 at 05:32
  • Suppose you are using DB to store your Sector details & using auto-incremented values for that. Then your Sector code will be like 1,2,3... so on. At the time of building drop-down button for Sector list use those sector codes as OPTION values in the drop-down list. Then, when the user selects any Sector from the drop-down list pick the option value(sector code) & search that Sector code in DB for all respective records. – Suresh May 17 '17 at 06:01
  • thank you very much for wasting your time for my problem. But if I implement as you described above, when a user searches it will show sector code or sector name? Because if I use sector code as option value only sector code will be stored in DB. Am I wrong? – Nahid Mirzayev May 17 '17 at 06:17
  • Yeah!!! Sector code will be in DB. Along with this, you can keep each sector code information (like respective sector name. ex 10 = Finance) in some other table. Then use all these information from different tables & generate whatever kind of UI you want. – Suresh May 17 '17 at 06:21
  • So I will store sector code on main table, then will create different tables for each language and put each sector with the same number. In the search result will fetch data from respective table according to the sector code. Right? – Nahid Mirzayev May 17 '17 at 06:30
  • Shared some table structure(in my above reply) for your reference. Hope that will give you some idea to how to handle your exact data in the context of your application. – Suresh May 17 '17 at 06:52
  • Thank you very much. Now I have clear mind about table structure. But now writing query for getting data from 3 tables seems a little bit complicated to me. Could you give an example also, please? :) – Nahid Mirzayev May 17 '17 at 07:05
  • I've updated those table structure a bit. Re-check once. About code... please HELP YOURSELF. ;) If stuck at anywhere create a different question with your sample code. Also, aceept the answer if it'll resolve your issue. – Suresh May 17 '17 at 07:08
0

You can work with parent-child structure which will allow you to work with multiple languages.

for example Languages are defined in all systems as tow char (ar,en,de,fr..etc).

So your table will be like this

sector table

id - sector_name       - parent_id - language
1  - Sector in English - null -       en 
2  - Sector in French  - 1    -       fr 
3  - Sector in Spain   - 1    -       sp
  • parent_id is a foreign key which will be null when the record is the parent and will have the parent id when the current record is child .

Your select statement will be like this

select * from sector where language="en" and (id=$id or parent_id=$id );

reference

http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/

How to create a MySQL hierarchical recursive query

Ahmad Samilo
  • 914
  • 16
  • 30