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 8905921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:31:02+00:00 2026-06-15T02:31:02+00:00

I am creating a multisite CMS with codeigniter and am having trouble with a

  • 0

I am creating a multisite CMS with codeigniter and am having trouble with a query for navigation links. Each page can have meta values that override the defaults (location_id = 0) with ones specific to the site if set. I have two tables cms_pages and cms_page_meta storing the information. Below is the relevant data

Table cms_pages
    page_id


Table cms_page_meta
    meta_id
    location_id
    page_id
    tag_name
    tag_value

I would like to do this in one call if feasible.

This is the call I was using, it causes pages to be listed twice if a title value exists for all locations (location_id = 0) and a specific location (location_id = x) where I just want the specific location if it exists otherwise the generic, otherwise NULL

SELECT cms_page.*, cms_page_meta.tag_value
FROM cms_pages
LEFT JOIN cms_page_meta ON cms_page_meta.page_id = cms_pages.page_id
WHERE cms_page_meta.location_id IN (0, x)
ORDER BY cms_pages.page_order`

I’m pretty sure I should to use coalesce but just can’t figure out how to implement it. Am I trying to do too much at once? Should I split the calls and process with PHP array_merge? I’d like to avoid that as I can cache the call and delete/regenerate the cache whenever I make a change to the pages or metadata. The server gets ~10,000 hits a day so speed is helpful but not necessary yet…

I changed the above query so it only grabs generic data for right now. Any help is greatly 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-06-15T02:31:04+00:00Added an answer on June 15, 2026 at 2:31 am

    I think you should use something like this:

    SELECT
      cms_page.*,
      COALESCE(cms_pm2.meta_id, cms_pm1.meta_id) as meta_id,
      COALESCE(cms_pm2.tag_name, cms_pm1.tag_name) as tag_name,
      COALESCE(cms_pm2.tag_value, cms_pm1.tag_value) as tag_value
    FROM
      cms_pages LEFT JOIN cms_page_meta cms_pm1
      ON cms_pm1.page_id = cms_pages.page_id
         AND cms_pm1.location_id = 0
      LEFT JOIN cms_page_meta cms_pm2
      ON cms_pm2.page_id = cms_pages.page_id
         AND cms_pm2.location_id = x      
    ORDER BY cms_pages.page_order
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a AIR application in flex. I have a textArea having a
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
I creating a web application using JSF,Hibernate,Spring. I have added a filter for checking
Creating a browser based single-page browser based RIA. Would like to make use of
Creating a Blackberry app. Just a beginner, I have searched but couldn't find a
i am creating multisite in drupal 6 in my local xampp server,could anyone help
I have the following webform: <%@ Page Language=C# AutoEventWireup=true CodeBehind=Default.aspx.cs Inherits=TestWebApp.Default %> <!DOCTYPE html
i am having a hard time creating a EditText which is multiline and width
Creating a ruby on rails site and recently added: <% if (?can :manage, :table)
Creating my WordPress author.php template page and ran into a little roadblock. I want

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.