ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

related entries inside query tag

June 24, 2007 3:13pm

Subscribe [2]
  • #1 / Jun 24, 2007 3:13pm

    Oxygen Smith

    120 posts

    Greetings all,

    I’m using a query to list only the set of entries in a weblog that have a custom drop-down field set to “yes.” This works just great, but I also need to display the title of a related entry. Inside of a query, however, I can only get an ID# of the related entry (which also doesn’t appear to be the same as the entry ID).

    Trying to nest queries gives me errors, and I can’t do a weblog entries tag inside the query either. I am wondering if I need to use PHP to pull the related info in, or would ‘joining’ tables in some way be recommended for getting info about related entries inside of a query?

    To make it more concrete, I’m setting up a complex discography, in which a weblog called “tracks” lists remixes and versions of “songs” in a “songs” weblog. Thus, each “track” is like an instance of a “song.” Here’s the query that produces a list of tracks with a drop-down field (its ‘downloadable’ setting) set to ‘yes.’

    {exp:query sql="SELECT t.entry_id, title, field_id_34 as songid, field_id_37 as tracklength, url_title FROM exp_weblog_titles AS t, exp_weblog_data AS d WHERE t.weblog_id=7 AND t.entry_id = d.entry_id AND field_id_70 ='yes' ORDER BY title"}
    
    {title} | {tracklength} | {songid}
    
    {/exp:query}

    The title of the related entry (the song entry’s title) is what I’m looking to display in here, rather than songid. Field_id_34 is the field in the “tracks” weblog where the title of the “related song” (that the track is a remix of) is chosen.

    I’m just hoping to be steered in the right direction toward the “recommended way of doing this…,” not having the work done for me or anything like that! I’m just wrapping my head around ‘joining’ tables now, but trying to figure out how to do in the context of ‘related entries’ is a challenge. It would be hugely helpful if someone could just recommend doing this either with PHP or a join in a query tag. Thanks so much!

    R o B

  • #2 / Jun 25, 2007 7:41pm

    Oxygen Smith

    120 posts

    OK, I edited the above so it’s clearer, I hope.

    Sorry, I know that related fields and weblogs always scare people off, too. (Or make them just glaze over…)

    Maybe someone could answer just this question to get me started. I am really curious about what the “number” is that’s returned by the query or weblog tag to display related fields when you don’t actually use the related_entries tag, and just try to display the related field by name. It doesn’t correspond to an entry_id or anything, but definitely uniquely identifies the related entry. Maybe something could be done with it in the query or PHP? I’ve used the database utility to look thru my database tables though to figure out where that’s being stored, but no dice.

    Or, is there just a thread that discusses how to handle related entry titles (and/or custom fields) within queries? I’ve looked and looked…

    For the time being, I may have a solution using Mark Huot’s custom fields in ee tags module that will allow me to back off to a standard weblog entries tag. If I have an extension taking care of being able to limit the weblog entries displayed to the ones with a ‘yes’ in the downloadable field, then I can just use “related entries” to display the title of the related entry field that I’m after.

    At the time of this writing, there were some issues with his extension and 1.6 (it involves a hack), so I may be grappling with PHP and queries again. And I’m still really curious about related fields and queries.

    Thanks for reading through this!

    Rob

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases