By Anthony Glover on Saturday, 24 May 2014
Posted in Technical Issues
Replies 3
Likes 0
Views 616
Votes 0
Hi everyone,

I'm trying to display a users fields data.

After some searching I found this page http://stackideas.com/forums/displaying-profile-custom-field-data which outlines the function used to get user data.

However this function is only for single values, it seems inefficient to call it lots of times. Is there a function to get all the user field data for a single user as an object?

Also, please update the docs http://docs.stackideas.com/developers/users/users with the getFieldData() function.
Hello Anthony,

If you are planning to just get "raw data from the database, then you can run a SQL query to retrieve this values. For example, if you want to get all user fields from a user,



This query above will return 2 columns:

1. data (Unformatted)
Unformatted data means the data isn't processed by the field apps yet. They are often stored as JSON strings.

2. raw (Raw data)
Raw data that is exactly what the user enters.
·
Saturday, 24 May 2014 14:33
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi Mark, thanks for the swift support!

I think you misunderstood, I didn't want to get every instance of a specific key in the database, I just wanted to retrieve a users data. The code you pasted is broken, the quotes and typos are preventing it from working.

I will past a working example here for other people having the same problem. Thanks for pointing me in the right direction though, it was a perfect starting point!

Raw query suggested, to retrieve all of a single unique key (birthday) from the DB

Select
b.data,
b.raw
From
uktnm_social_fields As a Inner Join
uktnm_social_fields_data As b On a.id = b.field_id And b.type = 'user'
Where
a.unique_key = "BIRTHDAY"


Raw query to get a users data. Getting data for user UID 32

Select
b.data,
b.raw
From
uktnm_social_fields As a Inner Join
uktnm_social_fields_data As b On a.id = b.field_id And b.type = 'user'
Where
b.uid = "32"


Final code, getting formatted, associated key data only for a single user (user UID 32) from the db

require_once(JPATH_ADMINISTRATOR . '/components/com_easysocial/includes/foundry.php');

$db = Foundry::db();
$query = array();

$query[] = "select b.data, a.unique_key from #__social_fields as a";
$query[] = "inner join #__social_fields_data as b";
$query[] = "on a.id = b.field_id";
$query[] = "and b.type=" . $db->Quote('user');
$query[] = "where b.uid=" . $db->Quote('32');

$db->setQuery($query);

$result = $db->loadAssocList('unique_key');




Which all works fine! However getFieldData also works on !Joomla standard data, an inbuilt method to get everything really would be handy.
·
Saturday, 24 May 2014 17:47
·
0 Likes
·
0 Votes
·
0 Comments
·
Thanks for updating Anthony and glad that you found a work around (Sorry I was blindly coding with gist earlier)
·
Saturday, 24 May 2014 23:41
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post