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.

Problem with Query Module

August 29, 2007 7:22pm

Subscribe [2]
  • #1 / Aug 29, 2007 7:22pm

    Jeri Letman

    23 posts

    I have a custom query that prints out fine.

    This code prints out all the records

    {exp:query limit="5" paginate="bottom" sql="SELECT commission_id,payment_id,receipt_id,product_id,affiliate_id,entry_date FROM exp_aff_commissions ORDER BY entry_date DESC"}

    when I try to limit the output to just the logged in member I used this statement

    {exp:query limit="5" paginate="bottom" sql="SELECT commission_id,payment_id,receipt_id,product_id,affiliate_id,entry_date FROM exp_aff_commissions WHERE affiliate_id ='{member_id}' ORDER BY entry_date DESC"}

    This outputs nothing. The SQL statement would print out values if the value of member_id was merged into the statement.

    I also tried this:

    {assign_variable:sql_statement="SELECT commission_id,payment_id,receipt_id,product_id,affiliate_id,entry_date FROM exp_aff_commissions where affiliate_id ={member_id}"}
    
    {exp:query limit="5" paginate="bottom" sql="{sql_statement} ORDER BY entry_date DESC"}

    That didn’t work either. I put {sql_statement} in the template to make sure that the SQL statement was correct, and it was.

    Am I missing something, or can this not be done?

    Thanks,

    Jer

  • #2 / Aug 29, 2007 8:22pm

    Derek Jones

    7561 posts

    Global variables are parsed at the very end of the template parsing, Jeri, so the Query is being executed before {member_id} is evaluated.  You need to use PHP on Input stage parsing and use:

    <?php global $SESS; echo $SESS->userdata['member_id'];?>
  • #3 / Aug 29, 2007 8:26pm

    Jeri Letman

    23 posts

    Thank you.

    I will do that.

    Jer

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

ExpressionEngine News!

#eecms, #events, #releases