-
☆ A M B ☆
- 24,524 Posts
You would first need to fetch the headings, then the subheadings, then the users for each subheading. You might be able to do it with one query, using group_concat.
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat
Thank you sottwell! I'll try this aproach.
valkovdesign.com
You might put the users in separate user groups, if they're not already, then you can just do this:
<?php
$userGroup = $modx->getObject('modUserGroup', array('name' => 'Germany'));
$users = $userGroup->getMany('UserGroupMembers');
foreach ($users as $user) {
$profile = $user->getOne('Profile);
/* do display stuff here */
$fullName = $profile->get('fullname');
$email = $profile->get('email');
}
------------------------------------------------------------------------------------------
PLEASE, PLEASE specify the version of MODX you are using.
MODX info for everyone:
http://bobsguides.com/modx.html
Thanks Bob, but should i manually create user groups for all possible countries? The idea is that there will be profiles from all over the world?
valkovdesign.com
-
☆ A M B ☆
- 24,524 Posts
That's why I first suggested getting all of the countries (select distinct), then the cities, then the users. There should be a way to make a single query using group_concat or something similar, then handle the results in arrays, without having to make so many queries.
Another option is to maintain a couple of relational tables, one for a list of countries, one for a list of cities with a field for country_id, and one to link city_id with user_id. It's just a series of one-to-many relationships; one country -> many cities, and one city -> many users.
That's getting into heavier relational database theory than I'm really comfortable with, but I suspect that xPDO would make it quite painless once it got organized properly.
[ed. note: sottwell last edited this post 14 years ago.]
I almost succeeded to get desired results by using GROUP_CONCAT. Echoed results directly from snippet show the list as in example above. I'll post the code when finish with it.
UPDATE: The problem now is when listing that way I can not make a link from "Fullname" to its profile, as the links i've generated to show user profiles end with: /profile.html?userId=n (using FURLs)
[ed. note: valkovdesign last edited this post 14 years ago.]
valkovdesign.com
Can't you just fetch the internalKey as well from the UserProfile table and use that field in your link?
-
☆ A M B ☆
- 24,524 Posts
Yes, that can be tricky if you don't realize that the user ID becomes the "internalKey" field in the other user tables.