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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:58:06+00:00 2026-05-26T22:58:06+00:00

I want to use field name to determine the column that I will use

  • 0

I want to use field name to determine the column that I will use to search for, but first I have to use the name to look up a column ID, then concatenate the column ID with a string to get the actual column name. I’m doing with with two queries now, but I’d like to combine them into a single query.

For example, I want to search for “fool=true”. In the first table, I find out that values for “fool” are in column 1 of the second table. In the second table, I do the real search, for “field_id_1=true”.

This table maps names to column IDs used in the second table.

exp_channel_fields
+field_id +field_name +
|---------|-----------|
|1        |fool       |
|2        |money      |
+---------+-----------|

This table has the data I want to search, but the column names don’t quite match the ID from the prior step. I have to prepend “field_id_” to the ID I found before:

exp_channel_data
+entry_id+field_id_1 +field_id_2 +
|--------|-----------|-----------|
|837     |true       |$500       |
|838     |false      |$50,000    |
+--------+-----------+-----------+

Here’s the first query I use, and I store the result into $myFieldID.

SELECT field_id as tField_id FROM exp_channel_fields 
WHERE field_name = 'fool'

Then I use the result to build the second query:

SELECT
    GROUP_CONCAT(entry_id ORDER BY entry_id SEPARATOR '|')
    AS result_entries
FROM exp_channel_data
WHERE field_id_{$myFieldID} = "true"

Is there a way to combine these into a single query? Thanks in advance!

  • 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-26T22:58:06+00:00Added an answer on May 26, 2026 at 10:58 pm

    it is not possible to use query-results as column names, but you can use server-side prepared statements to achieve a similar behavior. have a look at this question:

    MySQL concat() to create column names to be used in a query?

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

Sidebar

Related Questions

I want preserve original value of target field and use json_decode to use following
I want hide some fields in existed XML and use that XML as Input
I want use BYTE_ORDER macro in my Xcode project but i can't because i
i want use some data from a website with web service. i have a
I want use JQuery mobile for the front-end of my mobile application, but I
I want to use max clause to find the maximum value according to field
I have a Django model with multiple ImageFields and use a callable to determine
We frequently have users that create multiple accounts and then end up storing the
We have a User doc in Mongo DB and want to use the _id
I have a fairly complicated join query that I use with my database. Upon

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.