Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am looking for some help in building a sql to export specific data from the DB.

In BuddyPress, I have a profile field set up called Newsletter. I need to export a list of user from the db who have ticked the Yes (subscribe to newsletter).

I have identified the tables/fields in use in my DB.

SELECT `user_id` FROM `wp_bp_xprofile_data` WHERE `field_id` = 8 AND `value` LIKE 'yes'

Where user_id is the Registered user iD Where field_id 8 is my Newsletter value.

Now I need to link this with wp_user on user_id but don't know how to use 1 SQL on both table (sorry not my stuff).

Second table is wp_user where the Value of User_id should be "linked" to ID.

will appreciate some expert help

thx

RESOLVED AS

SELECT wp_users.ID , wp_users.user_email FROM wp_users LEFT JOIN wp_bp_xprofile_data ON wp_bp_xprofile_data.user_id = wp_users.ID , WHERE wp_bp_xprofile_data.field_id =8 AND wp_bp_xprofile_data.value = 'yes'

Field ID = 8 being the Field you want to get (in my example, newsletter) wp_bp_xprofile_data.value = Yes, being the value of my checkbox (ie Yes)

share|improve this question

closed as off-topic by birgire, ialocin, Wyck, Pat J, toscho Aug 16 at 0:48

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

    
Any help on this? –  salocin Feb 6 '12 at 14:03
    
This where I am stuck SELECT wp_users.ID , wp_users.user_email FROM wp_users LEFT JOIN wp_bp_xprofile_data ON wp_bp_xprofile_data.user_id = wp_users.ID, WHERE wp_bp_xprofile_data.field_id =8 AND wp_bp_xprofile_data.value = yes –  salocin Feb 6 '12 at 14:08
    
In case somebody need it, resolved it SELECT wp_users.ID , wp_users.user_email FROM wp_users LEFT JOIN wp_bp_xprofile_data ON wp_bp_xprofile_data.user_id = wp_users.ID , WHERE wp_bp_xprofile_data.field_id =8 AND wp_bp_xprofile_data.value = 'yes' –  salocin Feb 6 '12 at 14:29
3  
Please post your answer as an answer and not a comment. This will help others and stay true to the QA protocols. –  Brian Fegter Feb 6 '12 at 14:40

1 Answer 1

Since the asker really doesn’t want to post the answer … someone has to do it:

SELECT wp_users.ID , wp_users.user_email 
FROM wp_users 
    LEFT JOIN wp_bp_xprofile_data ON wp_bp_xprofile_data.user_id = wp_users.ID, 
    WHERE wp_bp_xprofile_data.field_id = 8 
    AND wp_bp_xprofile_data.value = 'yes'

field_id = 8 being the Field you want to get (in my example, newsletter) wp_bp_xprofile_data.value = 'yes', being the value of the checkbox.

share|improve this answer
    
Cheap rep. +1 ;) –  kaiser Oct 15 '12 at 18:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.