{"referred":"Through a friend","headshot":"77547235.jpeg","registerbtn":"1","rand_id":"137014","sample_report":"8.26.13_-Starbucks_1377560995.xls"}
$el = $modx->newQuery('modUserProfile');
$el->where(array('modUserProfile.city' => ''.$g->name.''));
$el->where(array('modUserProfile.extended' => 'Elance'));
$elance = $modx->getCollection('modUserProfile',$el);
$ret.='<td>'.count($elance).'</td>';This question has been answered by BobRay. See the first response.
$el = $modx->newQuery('modUserProfile');
$el->where(array('modUserProfile.city' => $g->name));
$el->where(array('modUserProfile.extended:LIKE' => '"referred":"Through a friend"'));
if ($elance = $modx->getCollection('modUserProfile',$el)){
$ret.='<td>'.count($elance).'</td>';
}you can not really search in json-fields, better would be to have your searchable datas stored in a custom-table.
<object class="extMyUser" extends="modUser">
<composite alias="MyProfile" class="extMyProfile" local="id" foreign="user" owner="local" cardinality="one" />
</object>
It is possible to do a brute-force search on extended fields by getting every profile in the DB and then using $profile->get('extended') and in_array() on each of them, but it would be very slow and memory intensive. If you don't expect to have a lot of users, it might be acceptable.
$matches = array();
$profiles = $modx->getCollection('modUserProfile');
foreach ($profiles as $profile) {
$extended = $profile->get('extended');
if ($extended && in_array('Elance', $extended, true) ) {
$matches[] = $profile;
}
}
/* At this point $matches is an array of the
profile objects that match the criterion */