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.

EE Query with php-var ?

March 20, 2012 6:21pm

Subscribe [2]
  • #1 / Mar 20, 2012 6:21pm

    hartstikkid

    4 posts

    Hello community,

    I am trying to give a value to a php-var and use this later on the page in an ee-query.
    Is this impossible or is there something wrong with my code ?

    {exp:channel:entries channel="test" studio_id="{segment_2}"}
    // a lot of irrelevant code here
    <?php
     $phpvar = "{residentie}";
     echo $phpvar; // this works > i see the value on the page
    ?>
    {/exp:channel:entries}
    
    // in this part i want to use the php-var in the query > this doesn't seem to work
    
    {exp:query sql="SELECT entry_id FROM exp_channel_data WHERE field_id_1 = '<?php echo $phpvar; ?>' "}
            entry_id : {entry_id} // no entry_id showed on the page
    {/exp:query}

    Any advice ???
    THX

  • #2 / Mar 20, 2012 8:02pm

    the3mus1can

    426 posts

    Actually that is not possible the way you have it now. If you set PHP to be parsed on Input, which is what you need to pass it into the query module, then the PHP variable value will not have been set yet because the entries loop will not have run yet.  You will need to put the query module code in an embed and pass in the PHP variable value to it.

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

ExpressionEngine News!

#eecms, #events, #releases