0
votes

I create some custom user profile fields, I just create a edit user profile plugin (adding the fields in profile.xml etc). Now when I create a user or edit it, I have classic profile fields(city, addres etc..) and my own fields. I create user profile page that display all the fields, but I'd like to edit this page. I'd like display only my fields or add some css class etc..

How can I edit it? Where can i found it?

In another way I create another page, with a php plugin I can add some code. How can I access to my custom fields? I tryed with http://docs.joomla.org/Accessing_the_current_user_object but I can only access to the default fields.

Does anyone know how to access these variables?

ps this is what I write in my article with php:


    $user =& JFactory::getUser();

    $userId = $user->id;

    $db = &JFactory::getDbo();
        $db->setQuery(
            'SELECT * FROM phs_user_profiles WHERE user_id = '.$userId.' AND profile_key      LIKE \'myfilevalue1.%\''
        );
    $results = $db->loadAssocList();
    if($results) echo $results[0]['profile_value'];
    else echo "dont work";

it display "dont work" :(

what's wrong with this code?

2
Whats the structure of your database file. For example do you not use #__phs_user_profiles using the joomla prefix? - George Wilson
I have already tried to use #__ but it's the same.. the error was in the query apostrophe ' :) - Edoz

2 Answers

0
votes

A simple way you need to edit com_users view (profile) and in the profile view you can access user on this by :-

$user =& JFactory::getUser();

 //firstly check you got this.  
echo  $userId = $user->id;
// then you can access all fields using userid.
    $db = &JFactory::getDbo();
    $query = "SELECT * FROM phs_user_profiles WHERE user_id = ".$userId;
        $db->setQuery($query);
    $results = $db->loadAssocList();
// print result using print_r($results); if you get
    if($results) echo $results[0]['profile_value'];
    else echo "dont work";

also check the link http://docs.joomla.org/Accessing_the_database_using_JDatabase

0
votes

First of all, you have specified you datatabase table incorrectly. You need to define the prefix using #__, for example #__content.

You should also change the following code:

if($results) echo $results[0]['profile_value'];
else echo "dont work";

to this:

if($results) { 
   echo $results[0]['profile_value'];
}
else { 
   echo "dont work";

}