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.

Help w/ Simple Query Select?

July 03, 2014 1:36am

Subscribe [2]
  • #1 / Jul 03, 2014 1:36am

    msmith29063

    75 posts

    I’m just trying to query one entry in the database to pull two custom date fields and create a simple PHP variable that I can use for conditionals throughout the page. Here’s what I currently have:

    {exp:query sql="SELECT field_id_452, field_id_453 FROM exp_channel_data WHERE entry_id = '77342'"}
    {if current_time >= field_id_452 AND current_time <= field_id_453}
    <?php $customVariable = 'y'; ?>
    {/if}
    {/exp:query}

    But this doesn’t work. $customVariable always outputs as “y”. I’m assuming it’s a parsing order issue (I have to use Output) because if I take out the PHP and just show/hide the “y” with EE—it works.

    What’s the quickest/simplest way to run the query and generate the variable? I tried to use the database class—but struggled with syntax.

    Any help you can provide would be greatly appreciated. Thank you.

  • #2 / Jul 08, 2014 4:36pm

    msmith29063

    75 posts

    Any thoughts on this? Thank you for any help you can provide.

  • #3 / Jul 21, 2014 11:23pm

    Elemento, Inc.

    57 posts

    Did you try:

    {exp:query sql="SELECT field_id_452, field_id_453 FROM exp_channel_data WHERE entry_id = '77342'"}
    <?
    $curr = "{current_time}";
    $f1 = "{field_id_452}";
    $f2 = "{field_id_453}";
    
    if($curr >= $f1 && $curr <= f2){
    $customVariable = "y";
    } else {
    $customVariable = "n";
    }
    
    ?>
    
    {/exp:query}

     

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

ExpressionEngine News!

#eecms, #events, #releases