• Resolved thisistrav

    (@thisistrav)


    Hi There,

    I’ve been spending waaaay too much time trying to figure this out on my own. Partly because I’m stubborn, party because it sounds like it should be relatively easy.

    I’m simply trying to display the value of a MSSQL DB field depending on the current user signed in.

    E.g. A customer, Bob, has a reference number of ABC123. Therefore, when user ‘bob’ logs in I want to be able to display ‘ABC123’ on a page (not profile).

    I searched everywhere for days but just can’t get it to work all together. I’d appreciate any guidance.

    Many thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter thisistrav

    (@thisistrav)

    OK, so all I apparently needed was another half a day.

    I used the plugin: Shortcode Exec PHP, then created a shortcode for the below code:

    global $wpdb;
    global $current_user;
    $current_user = wp_get_current_user();
    return $wpdb->get_var(“SELECT field FROM table WHERE field = ‘$current_user->user_login'”);

    … with “output echoed” unticked.

    The shortcode then easily placed in a page.

    I believe I was close on a number of occasions way back, but had the quotes mixed up on the $current_user->user_login variable.

    Glad that’s over. Next challenge now. Hope that might help someone else.

    Thread Starter thisistrav

    (@thisistrav)

    Sorry, testing code up there ^.

    With SQL injection protection on… last line reads…

    return $wpdb->get_var($wpdb->prepare(“SELECT field FROM table WHERE field = ‘$current_user->user_login'”));

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Displaying Database Data on a Page based on User’ is closed to new replies.