Re: Help with new function
Why are you not using the function bp_core_get_user_displayname() in bp-core.php? You can pass it the user’s ID and it will pull the username for you.
But, here’s what you need to do with your code:
$row = $wpdb->get_var( $wpdb->prepare("SELECT user_login FROM $wpdb->users WHERE id = %d", $bp->displayed_user->id) );
Also, note that this will only work when a viewer is on a member’s page as it pulls the ID of just that displayed user.