Navigation

Pligg Support

Hi all,
I doing a custom module to show a message alert to certain users, but I have due with how manage and access to users tables.

I have made a tpl inside in my module and I want to check if the user logged has a value in his profile. Could someone help me with that?

I have some thing like this:


{php}
global $db,$my_base_url,$my_pligg_base;
$userid = $current_user->user_id;
{/php}

some text to show certain user manage with one IF



Possible Answers

    Inside the php block, this is how you get the $user_id of the logged in user.

    $user_id = $main_smarty->get_template_vars('user_id');

    | Posted 122 days ago | Permalink | Hide Replies

    Well, where is this code, in what file and directory? If it is in a module, then $user_id = $current_user->user_id; won't work. You have to use the line of code I provided to get the $user_id and use it in your query. Check the \libs\smartyvariables.php to see the smarty variables available for you to use.

    {php}

    global $db,$main_smarty, $current_user;

    $user_id = $main_smarty->get_template_vars('user_id');

    $user_logged_in = $main_smarty->get_template_vars('user_logged_in');

    if($user_logged_in){

    $flag = $db->get_row("SELECT flag FROM pligg_users WHERE user_id = '$user_id' " );

    if ($flag) {

    //flag is true, do something

    }else {

    //flag is false

    }

    {/php}

    | Posted 122 days ago | Permalink | Hide Replies

    I have this code, but it doesnt work fine.

    * flag is a new field in user table that I have created.

    {php}

    global $db,$main_smarty, $current_user;

    $user_id = $current_user->user_id;

    if($current_user->user_login){

    $flag = $db->get_row("SELECT flag FROM pligg_users WHERE user_id = '$user_id' " );

    if ($flag) {

    //flag is true, do something

    }else {

    //flag is false

    }

    {/php}

    Any idea, what is wrong?

    Regards

    | Posted 122 days ago | Permalink | Hide Replies

Who Upvoted this Story

Pligg.com's Support area is where you can ask questions and get answers. Just getting started with the Support area? This section describes tips for participating.

Submitting a Question or Comment

By taking a minute to research previous posts you may receive an answer much faster than waiting for a response to a new question. Begin by searching the support section for an answer. Sometimes you may even want to extend your search to the entire pligg.com domain.

If you are unable to find a relevant answer, submit a new question or comment here. Please provide a detailed description and, when necessary, debugging information such as your server environment (a link to a <?php phypinfo(); ?> .php page would be very helpful), your web browser, and any steps necessary to reproduce your issue.

Submitting an Answer

If you have an answer or useful response that you would like to add to a post, you can submit it as a comment which other users will then vote on. Answers are sorted by most popular to least, allowing the best information to climb to the top of the page.

Please read and vote for existing answers before submitting your own, as there may already be an acceptable answer provided. You can use the "Reply" link found within an answer to submit a response to it, in case you want to expand or comment on someone else's contribution.

Including Files or Code

Sometimes it is necessary for you to attach a file or include a snippet of code for others to reference in your response. In most cases, you can .zip up files and attach them to a question or answer using Pligg's file manager. At times though this may fail, and in these circumstances we recommend using a third party host. Below we are including a list of recommended websites where you can share easily share file uploads (or snippets of code) through the web.