Simon Moon
10-18-2007, 09:50 PM
First of all, I am using PHP 5.2.4 and Mysql 5.0.45.
The problem I have here is a bit odd. I know a work around, but this is not satisfying. I know there is a way to do this with SQL, I am certain I have done this before even but hell, I can't find out when or where that was. For a couple of days I have been running in circles and I am sure the solution is too simple for me to stumble on it on my own by now.
One table, 3 fields: languageid (int), phrasename (string), phrasecontent (string).
First row: 0, test, Testing0
Second row: 2, test, Testing2
Now imagine the second row was no there. I am looking for the phrase with the name "test". In that case i get back "Testing0". Now the second row gets added. In this case i would get back two results, but I only want the one with the languageid 2.
Problem: I need ONE query (always the same) to return only ONE row in each case. The query needs to look for language id 2, but if it cant find the phrase it, will fall back on the phrase with the id 0 (who will always be there). If I can get this to work with one field, I should be able to create a list with that too.
The system I am creating is a multi language base system for a software. So these would be the translations, but the idea is to have a fall back on English in case it's not present in the "translated" version yet, or is not needed to be translated at all.
My Work around currently does the god awful thing of loading all phrases in english into an array with the phrasenames as keys then loads all the ones from the specific language, overwriting the values in the array where the keys match (because that phrase got translated). This can't be the solution, so I really would appriciate it if anyone has a good solution that would work in SQL.
The problem I have here is a bit odd. I know a work around, but this is not satisfying. I know there is a way to do this with SQL, I am certain I have done this before even but hell, I can't find out when or where that was. For a couple of days I have been running in circles and I am sure the solution is too simple for me to stumble on it on my own by now.
One table, 3 fields: languageid (int), phrasename (string), phrasecontent (string).
First row: 0, test, Testing0
Second row: 2, test, Testing2
Now imagine the second row was no there. I am looking for the phrase with the name "test". In that case i get back "Testing0". Now the second row gets added. In this case i would get back two results, but I only want the one with the languageid 2.
Problem: I need ONE query (always the same) to return only ONE row in each case. The query needs to look for language id 2, but if it cant find the phrase it, will fall back on the phrase with the id 0 (who will always be there). If I can get this to work with one field, I should be able to create a list with that too.
The system I am creating is a multi language base system for a software. So these would be the translations, but the idea is to have a fall back on English in case it's not present in the "translated" version yet, or is not needed to be translated at all.
My Work around currently does the god awful thing of loading all phrases in english into an array with the phrasenames as keys then loads all the ones from the specific language, overwriting the values in the array where the keys match (because that phrase got translated). This can't be the solution, so I really would appriciate it if anyone has a good solution that would work in SQL.