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.

Fetching Member Id Value on dynamic

December 14, 2012 8:04am

Subscribe [2]
  • #1 / Dec 14, 2012 8:04am

    bhumika

    8 posts

    Hi , I am phasing a problem to pass the login member is on query , below is my example

    <?php
    $id=”{member_id}”;
    echo $q = “SELECT * FROM exp_members WHERE member_id = ‘“.$id.”’”;
    $sql = mysql_query($q) or die(mysql_error());
    $var = mysql_fetch_array($sql);
    print_r($var);
    ?>

    In above example , How to pass Member_id on query. My result set value is coming blank on this .

    Can any one suggest me , how to pass member_id on query .

    Even also i have tired to below code

    {exp:query sql="SELECT first_name FROM exp_members where member_id=<?php echo $id;?>"}
                {first_name}
              {/exp:query}
    first_name value is not coming ,

    If I have pass static id then i got result.

    Thanks

  • #2 / Dec 14, 2012 10:19pm

    Bhashkar Yadav

    727 posts

    Hi Bhumika,

    There is no need to write the query for member data. You can populate the member profile data with its own tag like:

    {exp:member:custom_profile_data}
    {first_name}
    {/exp:member:custom_profile_data}

    Take more reference from here: http://ellislab.com/expressionengine/user-guide/modules/member/index.html#other-member-fields


    Best Regards,

  • #3 / Dec 15, 2012 6:25pm

    Gareth Davies

    491 posts

    Bhashkar’s solution is the simplest but you can also access the ExpressionEngine session class if you wanted a php solution:

    http://ellislab.com/expressionengine/user-guide/development/usage/session.html

    So to get the member id:

    echo $this->EE->session->userdata('member_id')

     

  • #4 / Dec 15, 2012 10:17pm

    Bhashkar Yadav

    727 posts

    Yes, there is PHP solution also.

    $this->EE =& get_instance();
    $member_id = $this->EE->session->userdata('member_id');
    
    {exp:query sql=“SELECT first_name FROM exp_members where member_id='<?=$member_id?>'”}
    {first_name}
    {/exp:query}

    Make sure for the template preferences “Allow PHP?” : “Yes”, “PHP Parsing Stage” : “Input”


    Best Regards,

  • #5 / Dec 17, 2012 12:43am

    bhumika

    8 posts

    Hello, Php is working Fine. Thank you so much

    but As par below logic , It is not working ,  If any other configuration are required ?

    {exp:member:custom_profile_data}
    {first_name}
    {/exp:member:custom_profile_data} 


    Regards
    Bhumi

  • #6 / Dec 17, 2012 4:06am

    Bhashkar Yadav

    727 posts

    Hmmm, it should always work. Which version of Expression Engine you are using?
    Is it old freelancer licence?


    Best Regards,

  • #7 / Dec 17, 2012 4:51am

    bhumika

    8 posts

    Hello,

    I am using the version - v2.4.0


    Regards
    bhumi

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

ExpressionEngine News!

#eecms, #events, #releases