Skip to:
Content
Pages
Categories
Search
Top
Bottom

How do you list all of the values in a profile field?

  • @theeasybutton

    Participant

    Example:

    I created a profile field called “state”. It’s in group 1. The values are all of the states in the USA.

    On the index, I would like to show a list of the options that people could choose. (in this example, it would simply be a list of states)

    Basically, I need a list of all the values like what you would see on the edit profile page, yet there’d be no editing. It’s just a list of text.

    (I hope that made sense. It barely makes sense to ME.)

Viewing 9 replies - 1 through 9 (of 9 total)
  • @r-a-y

    Keymaster

    Hey Chris,

    I’m assuming you’re using one of the prebuilt fields called “State”.

    I didn’t look too closely at the classes or template tags, but check out /buddypress/bp-xprofile/bp-xprofile-classes.php.

    There’s a function called “get_prebuilt_field_data()” that might help you out there.

    You’d have to pass the CSV file to that function, but that might help…

    Another way to output the “State” data would be to parse the actual CSV itself that is used for the data. The CSV can be found in buddypress/bp-xprofile/prebuilt-fields/states.csv.

    Hope that helps somewhat!

    @theeasybutton

    Participant

    I have no clue what CSV is. LOL I’m not using the prebuilt. That was just an example.

    Another example: Hair color — values are red, blonde, brunette. On the index page, that’s what I want people to see. i.e. “People at our site have hair that is: red blonde brunette”

    (goofy example lol)

    I’ve gone through the class files as well as the template tag files and just can’t get it worked out. I think that what I need is whatever makes the edit profile page show the list.

    I’ll take a look at those prebuilt field files and see if anything clicks in my tired old brain.

    Also, I tried using the profile loop “stuff” but it always gives me an error like “Fatal error: Call to a member function the_profile_field() on a non-object “

    @r-a-y

    Keymaster

    Ahh okay… forget my last post entirely then! haha.

    Not sure if this will work at all…

    $myxprofileFields = new BP_XProfile_ProfileData::get_value_byfieldname('Hair Color');

    echo $myxprofileFields();

    This is where my knowledge of PHP stops here!

    I’m not that great with classes and objects.

    @kunal17

    Participant

    Thanks Ray,

    I need to be able to list all the data in a particular profile field too. I will try your method as soon as possible and check if its working. For my next step, I need to figure out how to automatically create an xml file with all the data in a particular profile field.

    Can anybody suggest ways to do this?

    @plrk

    Participant

    I’m not sure what you want to do, but with this code, you can get a list of the options and the amount of users who have selected the option. Note: for selectbox and radio fields only.

    $field_id = 1; // this should be the id of the
    // field you want, see your wp_bp_xprofile_fields
    // database table to find it

    global $wpdb;

    $sql = "SELECT value FROM {$wpdb->base_prefix}bp_xprofile_data WHERE field_id = {$field_id} ORDER BY id DESC";
    $result = $wpdb->get_col($wpdb->prepare($sql));
    foreach($result as $row){
    if(strlen($row) > 0){
    $values[$row]++;
    }
    }
    $i = 0;
    foreach($values as $key => $value){
    $i++;
    if($i != 1){
    echo ", ";
    }
    echo $key . "(" . $value . ")";
    }

    @theeasybutton

    Participant

    Thanks – I’ll give both sets of codes a try. To answer the question of “exactly what I want to do” ….

    I want a search box. And instead of typing something in, they can use a pull down that will automatically translate into something like http://domain.com/members/?s=VALUE This way, the full list of values is listed for them and they don’t have to guess. i.e. location, number of kids, male/female. Things of that nature.

    @theeasybutton

    Participant

    Plrk, your code ALMOST works for me…. so dang close!!!!!!!!

    One member has chosen Fiction and Science Fiction. Here is the output that your code gives

    a:2:{i:0;s:7:”Fiction”;i:1;s:15:”Science Fiction”;}(1)

    Any idea how to get the extra garbage out of there and just list Fiction and Science Fiction”

    @djpaul

    Keymaster

    That’s what an array in the database looks like. Wrap that in a call to maybe_unseralize().

    @theeasybutton

    Participant

    I apologize for not coming back sooner to say this is solved. Been having lots of computer issues. The reason the other code didn’t work was we were reading from the wrong table. Another table had the info we needed so I swapped it out and here’s what I’m using now. Hopefully this will come in handy for a lot of people.

    This goes in the head

    <!-- drop down search -->
    <SCRIPT LANGUAGE="JavaScript">
    function formHandler(form){
    var URL = document.form.site.options[document.form.site.selectedIndex].value;
    window.location.href = URL;
    }
    </SCRIPT>
    <!-- end drop down search -->

    And this goes in the body

    <!-- drop down search -->
    <form name="form">
    <select name="site" size=1>
    <option value="">Blah Blah</option>
    <?php
    $field_id = 2; // this should be the id of the
    // field you want, see your wp_bp_xprofile_fields
    // database table to find it

    global $wpdb;

    $sql = "SELECT name FROM {$wpdb->base_prefix}bp_xprofile_fields WHERE parent_id = {$field_id} ORDER BY id DESC";
    $result = $wpdb->get_col($wpdb->prepare($sql));
    foreach($result as $row){
    if(strlen($row) > 0){
    $values[$row]++;
    }
    }
    foreach($values as $key => $value){
    echo "<option value=\"members/?s=$key\">$key</option>";
    }
    ?>
    </select>
    <input type=button value="Go!" onClick="javascript:formHandler(this)">
    </form>
    <!-- end drop down search -->

    Don’t forget to change the number of the field. Thanks for all of your help =D

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How do you list all of the values in a profile field?’ is closed to new replies.
Skip to toolbar