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.

question

July 01, 2007 4:49am

Subscribe [2]
  • #1 / Jul 01, 2007 4:49am

    Mejbaol Sajib

    5 posts

    Why this code is not running?

    <?php
    
    
    $sql = "SELECT title,entry_date,url_title,t.entry_id,comment_total,screen_name,field_id_15 AS unique_id,field_id_5 as description,field_id_7 as post_category,field_id_16 as video_link,view_count_one,rating_avg FROM exp_weblog_titles t, exp_weblog_data d,exp_members m WHERE t.entry_id = d.entry_id AND t.weblog_id=2 AND m.member_id=t.author_id and t.author_id='{member_id}'";
    
    
    if('{segment_3}'=="view_count")
         $sql=$sql." order by view_count_one desc ";
    else if('{segment_3}'=="rating")
         $sql=$sql." order by rating_avg desc ";
    else
         $sql=$sql." order by entry_date desc ";
    echo $sql;
    
    ?>
    
    
    
           <div>
     {exp:query limit ="5" sql="<?php echo $sql; ?>"}
           {if no_results}
                    <div class="generalWindow">You Have no Video!! 
     
     
    </div>
           {/if}
                    {embed="site/list_entry" cur_unique_id="{unique_id}" cur_url_title="{url_title}" cur_title="{title}" cur_description="{description}" cur_entry_id="{entry_id}" cur_edit_delete="{segment_2}"}
            
    {paginate}  Page {current_page} of {total_pages} pages {pagination_links} {/paginate}
        
    {/exp:query}
        
                        
            </div>

    but if hard code with ‘1’,‘2’ in place of ‘{member_id}’ it works…. why?

    can anybody rescume me?
    thanks in advace

  • #2 / Jul 01, 2007 11:06am

    Mejbaol Sajib

    5 posts

    is there any body to help me out?

  • #3 / Jul 06, 2007 1:11pm

    bigmikestudios

    22 posts

    I think the problem is the parsing order with PHP on this template. If you are parsing php first, then the expression engine variables (the ones in curly braces{}) won’t be available to you.

    You can use the $SESS class in php to get the member id - try this:

    $member_id = $SESS->userdata[‘member_id’];

    $sql = “SELECT title,entry_date,url_title,t.entry_id,comment_total,screen_name,field_id_15 AS unique_id,field_id_5 as description,field_id_7 as post_category,field_id_16 as video_link,view_count_one,rating_avg FROM exp_weblog_titles t, exp_weblog_data d,exp_members m WHERE t.entry_id = d.entry_id AND t.weblog_id=2 AND m.member_id=t.author_id and t.author_id=$member_id”;

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

ExpressionEngine News!

#eecms, #events, #releases