Skip to:
Content
Pages
Categories
Search
Top
Bottom

MySQL Query for Current Member


  • enda77
    Participant

    @enda77

    I have a table which pulls data from MySQL and it works fine for the current user but I want it to pull data from the database for the member page that I am looking at and not for the current user ID.

    Is there an equivalent to “where post.ID = %CURRENT_USER_ID%” for current member in buddypress?

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)

  • shanebp
    Moderator

    @shanebp


    enda77
    Participant

    @enda77

    Thanks shanebp,
    I’m probably doing something fundamentally incorrect here but ive replace the %CURRENT_USER_ID% section of MySQL query with bp_displayed_user_id() and it gives me errors.
    I am running the query inside the wpdatatables plugin so its not a true MySQL query form.
    My code is below, if you have a time could you take a look. Query runs fine when I replace bp_displayed_user_id() with an integer.
    Thanks

    SELECT wpyn_ks_trick_post.ID, 
    wpyn_ks_trick_post.TrickID, 
    wpyn_ks_trick_post.LevelID, 
    wpyn_ks_trick_post.Verified, 
    wpyn_ks_trick_post.VerifiedBy, 
    wpyn_kstricklist.TrickID, 
    wpyn_kstricklist.Category, 
    wpyn_kstricklist.TrickName, 
    wpyn_kstricklist.TrickDescription, 
    wpyn_kstricklist.Points, 
    wpyn_kstricklist.Grade 
    FROM wpyn_ks_trick_post
    LEFT JOIN wpyn_kstricklist 
    ON wpyn_ks_trick_post.TrickID = wpyn_kstricklist.TrickID 
    where wpyn_ks_trick_post.ID = bp_displayed_user_id()

    shanebp
    Moderator

    @shanebp

    > Query runs fine when I replace bp_displayed_user_id() with an integer.

    You need to adjust your sql so that it uses a variable.
    Try something like :

    $user_id = bp_displayed_user_id(); 
    ... where wpyn_ks_trick_post.ID = $user_id

    This is a basic php / mysql issue. There are lots of tutorials on the subject.


    enda77
    Participant

    @enda77

    Thanks for the help Shane, I’ll play around with it.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar