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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:05:27+00:00 2026-06-16T14:05:27+00:00

I wonder if any can help me understand something I’m trying to solve. I’m

  • 0

I wonder if any can help me understand something I’m trying to solve.

I’m working on a wordpress site but this is more a sql question as I’m just querying to get some results within a template file.

I have a gallery of pictures which are advert boxes, and I need to pull these in relation to a supplied movie name, to do this Im using some custom fields on the ad pic called ‘adlink’ (link off ad) and ad

I’m using the nextgen gallery plugin and querying those tables, and I have three tables in total that contain the data I need to query.

ngg_pictures, nggcf_field_values & nggcf_fields.

the nggcf tables are custom fields tables,

I have got so far I can get what I need in two seperate queries, but I can’t combine these into one query as it means querying the nggcf_field_values table twice, which I can’t seem to sort.

I have hardcoded the search criteria in for the mo, but the ‘close-encounters’ bit would be a passed var, and the ‘156’ would be the pid from the first query.

SELECT `eg_ngg_pictures`.`filename`, `eg_nggcf_field_values`.`fid`, `eg_nggcf_field_values`.`pid`
FROM eg_ngg_pictures, eg_nggcf_field_values
WHERE ((`eg_nggcf_field_values`.`field_value` LIKE 'close-encounters') AND (`eg_nggcf_field_values`.`pid` = eg_ngg_pictures.pid))



SELECT `eg_nggcf_field_values`.`field_value`
FROM eg_nggcf_field_values, eg_nggcf_fields
WHERE ((`eg_nggcf_fields`.`field_name` = 'adlink') AND (`eg_nggcf_fields`.`id` = eg_nggcf_field_values.fid) AND (`eg_nggcf_field_values`.`pid`  = '156'))

any help would be greatly appreciated, I can get the results with what I have, but I like to understand how to combine these two and write better SQl. Thanks MRO

  • 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-16T14:05:28+00:00Added an answer on June 16, 2026 at 2:05 pm

    After looking at the WordPress extension, I think the eg_nggcf_fields is the table that contains the name for a custom field. The eg_nggcf_field_values table contains the values of that custom field per picture.

    So if you’re looking for two fields called moviename and adlink, you have to look up two rows in the field_values table. You can join a table twice if you give it a different alias:

    select  pic.filename
    ,       pic.pid
    ,       fv1.field_value as MovieName
    ,       fv2.field_value as Adlink
    from    eg_ngg_pictures pic
    inner join -- Find ID for the field called 'moviename'
            eg_nggcf_fields f1
    on      f1.field_name = 'moviename'
    inner join -- Find value for field moviename for this picture
            eg_nggcf_field_values as fv1
    on      fv1.pid = pic.pid
            and fv1.fid = f1.fid
    inner join -- Find ID for the field called 'adlink'
            eg_nggcf_fields f2
    on      f2.field_name = 'adlink'
    inner join -- Find value for field adlink for this picture
            eg_nggcf_field_values as fv2
    on      fv2.pid = pic.pid
            and fv2.fid = f2.fid
    where   fv1.field_value like 'close-encounters'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I wonder if anyone can help, I'm trying to create a responsive site
wonder if anyone can help - I thought I had solved this but i
wonder if anyone can help. Bascially I'm working on a site, and a chunk
Looking at this related SO question , I can't help but wonder about the
I wonder whether someone can help me please. I've put together this page which
I wonder if you can help me. I am trying to extract a list
Hope someone can help with this: Am trying to delete session files on /tmp
I wonder if any of you guys can help me with what I think
I wonder if any of you could help with this problem. The following code
I wonder if someone here can help me figure out this problem. I need

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.