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.

Parse order Query module workaround?

December 03, 2010 5:07pm

Subscribe [4]
  • #1 / Dec 03, 2010 5:07pm

    Marc Miller

    84 posts

    I’m using a simple relationship custom field that stores other weblog entry IDs. If the default none is selected, nothing is set in the database. It’s a blank field.

    I then run the following if statement and query. Logic would say, if the custom field is blank, then don’t run the query at all. But because of the way EE parses, the Query is first.

    This is causing problems when the custom field is not set. The MySql query is running, looking for entry_id = blank, and then the page breaks.

    {if my_custom_field !=""}{exp:query sql="SELECT title AS qtitle, url_title AS qurl FROM exp_weblog_titles WHERE entry_id={my_custom_field}"}<a href="/linkto/{qurl}/">Visit {qtitle} Page</a>{/exp:query}{/if}

    So what’s the correct workaround here? Is there a way to force the page to run the MySql query after the EE if statements? Do I need to hack the plugin to use 0 for none so at least there is a number in the db?

    EE 1.7.0

  • #2 / Dec 04, 2010 5:42pm

    Greg Salt

    3988 posts

    Hi Marc,

    What do you mean by ‘hack the plugin’? Is {my_custom_field} a 3rd party field or a default EE relationship type field?

    Cheers

    Greg

  • #3 / Dec 06, 2010 5:05pm

    Marc Miller

    84 posts

    It’s the MD Simple Relationship extension. My field is optional, so if something isn’t selected, then nothing gets put into the database. It’s a blank field. So my hack idea was to make sure that if NONE was selected (by default or otherwise), then a 0 gets put into the database so at least there is something there for the SQL query to execute on, even if it returns 0 results.

    But as it stands now, the whole page dies if that column is blank. It would be nice if the SQL query didn’t run at all to begin with if the column is blank.

  • #4 / Dec 07, 2010 4:19am

    John Henry Donovan

    12339 posts

    Marc,

    Does something like this work? Make sure you add your apostrophes around your custom field too

    {if my_custom_field !=""}
    {exp:query sql="SELECT title AS qtitle, url_title AS qurl FROM exp_weblog_titles WHERE entry_id='{my_custom_field}'"}<a href="/linkto/{qurl}/">Visit {qtitle} Page</a>{/exp:query}
    {if:else}
    Field is empty
    {/if}
  • #5 / Dec 07, 2010 11:34am

    Marc Miller

    84 posts

    Single quotes around the custom field in the query. Doh.

    That was it. Thanks John!

  • #6 / Dec 07, 2010 5:06pm

    Ingmar

    29245 posts

    Excellent. Please post again as needed.

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

ExpressionEngine News!

#eecms, #events, #releases