BuddyDev

Search

[Resolved] Check if checkbox have data and print corresponding member name


  • Participant
    Level: Initiated
    Posts: 10
    Pause on #21378

    Hi,
    i have about 40 members on BP now. When registrating, member can choose from checkbox whether they are providing products.

    Case:
    Members have checked three from total of five options from a checkbox.
    Now I need to loop through all members who have checked checkbox value and print their names.
    If members has checked value from checkbox then print his/her member name.

    With this I can print all checkbox values from one user.
    $data = bp_get_member_profile_data( array( field=>CheckBox Or Select Field Name,user_id => $user_id ) );
    echo $data;

    https://buddydev.com/fetching-and-showing-only-specific-fields-from-buddypress-xprofile-data/


  • Keymaster
    (BuddyDev Team)
    Posts: 10538
    Brajesh Singh on #21403

    Hi Pause,
    Thank you for the question.

    I am sorry but I still unsure of the question.

    1. Do you want to list all users who have selected(checked) some of these option and then show them as well as their choices.

    2. Or do you want to list all users who have checked a specific choice? This will be a bit difficult for large number of users(40 is fine).

    PS:- Will you have a lot more users in future or is it going to be limited to few users? I am asking to help me provide you more efficient solution.

    Thank you
    Brajesh


  • Participant
    Level: Initiated
    Posts: 10
    Pause on #21428

    1. Do you want to list all users who have selected(checked) some of these option and then show them as well as their choices.
    – I want to list all users (and link to their member page) who have selected(checked) certain option, for example if users have checked option “milk” then list all users of that choice and show link to their member page.

    2. Or do you want to list all users who have checked a specific choice? This will be a bit difficult for large number of users(40 is fine).
    – Yes, specific choice from checkbox group and then show link to their member page.

    PS:- Will you have a lot more users in future or is it going to be limited to few users? I am asking to help me provide you more efficient solution.
    – max. 40-50 user will be total.


  • Participant
    Level: Initiated
    Posts: 10
    Pause on #21503

    Hi,

    any solutions for this yet?


  • Keymaster
    (BuddyDev Team)
    Posts: 10538
    Brajesh Singh on #21520

    Hi Pause,
    I will be assisting you today.

    Thank you
    Brajesh


  • Participant
    Level: Initiated
    Posts: 10
    Pause on #21534

    Ok.


  • Keymaster
    (BuddyDev Team)
    Posts: 10538
    Brajesh Singh on #21543

    Hi,
    Thank you for the patience.

    You can use the following query to fetch all users which have checked a specific option

    
    	$user_query = new BP_User_Query(
    		array(
    			'xprofile_query'  => array(
    				array(
    					'field'   => 16, // field id or name.
    					'value'   => 'multiselectbox 1', // value.
    					'compare' => 'LIKE',
    				),
    			),
    			'populate_extras' => false,
    		)
    	);
    
    	$user_ids = $user_query->user_ids;
    

    Make sure to change the value and the field id with your own.

    I hope you can take care of the loop to display the users from there.

    Regards
    Brajesh


  • Participant
    Level: Initiated
    Posts: 10
    Pause on #21546

    Ok,

    how can I print something out ? I only get “Array” text printed.
    I need to get this working outside of member page.

    <?php
    $user_query = new BP_User_Query(
    array(
    ‘xprofile_query’ => array(
    array(
    ‘field’ => 81, // field id or name.
    ‘value’ => ‘Hammer’, // value.
    ‘compare’ => ‘LIKE’,
    ),
    ),
    ‘populate_extras’ => false,
    )
    );

    $user_ids = $user_query->user_ids;
    ?>


  • Keymaster
    (BuddyDev Team)
    Posts: 10538
    Brajesh Singh on #21547

    The code gives you an array of the user ids who have that specific data in their profile. Now, you can loop through it anywhere and print the related information for users. It can be used at any place.

    You need to decide on what you want to fetch and print for each user.

    Please look at xprofile_get_field_data() for fetching field data for a user.

    Regards
    Brajesh


  • Participant
    Level: Initiated
    Posts: 10
    Pause on #21549

    Ok,

    can I have example 🙂 – I’m bit of confused right now.

The topic ‘ [Resolved] Check if checkbox have data and print corresponding member name’ is closed to new replies.

This topic is: resolved
Subscribe