php - Multilingualism website display Post by language or defaultGet the solution ↓↓↓
I am programming a Multilingualism website with symfony my article table:
|1||1||1||1||en||2021-02-16 00:01:00||pede libero En|
|2||1||1||1||fr||2021-02-16 00:02:00||pede libero Fr|
|3||1||1||1||*||2021-02-16 00:03:00||pede libero All|
|4||4||1||1||fr||2021-02-16 00:04:00||rhoncus aliquet Fr|
|5||4||1||1||*||2021-02-16 00:05:00||rhoncus aliquet All|
if you return only one record each time and always you return '*' if you can't find your desired lang, one way is :
SELECT TOP 1 * FROM App\Entity\Article a WHERE a.lang IN ( 'es', '*') GROUP BY a.original ORDER by a.lang DESC , a.updatedAt DESC
but bullet proof way is to :
SELECT * FROM `articles` WHERE (lang = 'fr' OR ( not exists(select 1 FROM `articles` WHERE lang = 'fr') and lang = '*' ) ) GROUP BY original_id ORDER BY updated_at DESC
Share solution ↓
Link To Answer People are also looking for solutions of the problem: sqlstate[hy000]  access denied for user 'root'@'localhost'
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
About the technologies asked in this question
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
Symfony compares favorably with other PHP frameworks in terms of reliability and maturity. This framework appeared a long time ago, in 2005, that is, it has existed much longer than most of the other tools we are considering. It is popular for its web standards compliance and PHP design patterns.
Welcome to programmierfrage.com
programmierfrage.com is a question and answer site for professional web developers, programming enthusiasts and website builders. Site created and operated by the community. Together with you, we create a free library of detailed answers to any question on programming, web development, website creation and website administration.
Get answers to specific questions
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Help Others Solve Their Issues
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.