Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 932633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:42:04+00:00 2026-05-15T20:42:04+00:00

I’m wondering the following, the query below will select the appropriate fields if a

  • 0

I’m wondering the following, the query below will select the appropriate fields if a language is set.

First question, I need the fields, title, keywords and description from the pages table or, if the language matches and the field is not null the page_langs table. Now I do this with three IF statements, is it possible to do this in a single IF?

Below query works and the array returned is something like this:

Array ( [0] => Array ( [Page] => Array ( [id] => 2 [lft] => 2 [rght] => 7 ) [0] => Array ( [title] => Welcome [keywords] => welcome [description] => welcome ) ) ) 

So, the id, lft, and rght are ‘within the Page (-> pages AS Page) array’, the title, keywords and description are outside the Page array, makes sense offcourse, but how do I get those three fields within the Page array, so I can use arr[Page][title] to retrieve the title instead arr[0][title]?

$sql = "SELECT Page.id, Page.lft, Page.rght, 
                IF (STRCMP(Lang.title, '') AND 
                    !STRCMP(Lang.langident, '{$lang}'), Lang.title, Page.title) AS title,
                IF (STRCMP(Lang.keywords, '') AND 
                    !STRCMP(Lang.langident, '{$lang}'), Lang.keywords, Page.keywords) AS keywords,
                IF (STRCMP(Lang.description, '') AND 
                    !STRCMP(Lang.langident, '{$lang}'), Lang.description, Page.description) AS description
            FROM pages AS Page 
                LEFT JOIN page_langs AS Lang
            ON Lang.parent_id = Page.id AND Lang.langident = '{$lang}'
                WHERE Page.id = {$id}"

Any help (suggestions about the query maybe?) appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:42:05+00:00Added an answer on May 15, 2026 at 8:42 pm

    I need the fields, title, keywords and
    description from the pages table or,
    if the language matches and the field
    is not null the page_langs table.

    SELECT
      COALESCE(Lang.title, Page.title) AS title
      /* ... etc ... */
    FROM
      pages AS Page 
      LEFT JOIN page_langs AS Lang ON Lang.parent_id = Page.id 
                                      AND Lang.langident = '{$lang}'
    WHERE
      Page.id = {$id}
    

    Since you left-join against the page_langs table with the correct language only, there is no need to check the language code again in the SELECT expression.

    If the translation is there, it will be the correct language right away. If the correct language is missing, it will be NULL, hence COALESCE() is sufficient.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.