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.

Query module: member_id doesn’t work?

April 21, 2008 3:18am

Subscribe [3]
  • #1 / Apr 21, 2008 3:18am

    michaelb

    21 posts

    Hey all,

    I’m trying to run a query using the {exp:query} module, but I’m running into an issue. I want to use the {member_id} in the query, but for some weird reason it’s not actually replacing the {member_id} within the query. It works inside the {exp:query} tags normally, so I’m a bit lost…

    Sample code to try:

    <h1>{member_id}</h1>
    {exp:query sql="SELECT c.cat_id FROM exp_categories c, exp_category_field_data f WHERE c.cat_id = f.cat_id AND f.field_id_12 = '{member_id}' AND cat_url_title = '{segment_4}' LIMIT 1"}
    <h2>Query 1: {member_id}</h2>
    <p>{/exp:query}</p>
    
    <p>{exp:query sql="SELECT * FROM exp_categories LIMIT 1"}</p><h2>Query 2: {member_id}</h2>
    <p>{/exp:query}

    Actual output from SQL debugging (Query 1):

    SELECT c.cat_id FROM exp_categories c, exp_category_field_data f WHERE c.cat_id = f.cat_id AND f.field_id_12 = '{member_id}' AND cat_url_title = 'test' LIMIT 1

    Note that the {member_id} is left without replacement…

    Mod Edit: Moved to the Technical Support forum.

  • #2 / Apr 22, 2008 11:34am

    Greg Aker

    6022 posts

    Mod Edit: Moved to the Technical Support forum.
    Mod Edit: Moved to the Core Technical Support (no licence found)


    Are you working on a Personal/Commercial License or the Core Version.  If you are working with the Core version, there is no query module.

    Does that help?

  • #3 / Apr 22, 2008 7:41pm

    michaelb

    21 posts

    I definitely am working on a Commercial license, I just didn’t email the EE people with my license key so this post was moved. Queries all seem to work, except when I try to use the {member_id} tag.

  • #4 / Apr 22, 2008 8:41pm

    Derek Allard

    3168 posts

    Hey Michael.

    Global variables like member_id aren’t parsed until well after tags are, so this won’t work.  What we need to do is grab the member id earlier in the process.  To do this, you could enable PHP in the template (on input), and run this.

    <?php
    global $SESS;
    $member_id = $SESS->userdata['member_id'];
    ?> 
    
    {exp:query sql="SELECT c.cat_id FROM exp_categories c, exp_category_field_data f WHERE c.cat_id = f.cat_id AND f.field_id_12 = '<?php echo $member_id;?>' AND cat_url_title = '{segment_4}' LIMIT 1"}
    <h2>Query 1: {member_id}</h2>
    <p>{/exp:query}

  • #5 / Apr 22, 2008 8:46pm

    michaelb

    21 posts

    Hey Derek,

    Thanks for that, I basically fell back to that in case there wasn’t an easy solution to this problem.

  • #6 / Apr 22, 2008 8:49pm

    Derek Allard

    3168 posts

    My pleasure sir, parse issues get the best of all of us from time to time.  Sorry you got bounced around like you did, but sounds like everything’s fixed up now, so I’m going to mark this thread resolved.

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

ExpressionEngine News!

#eecms, #events, #releases