Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Members in a group that have logged in more than once


Reply


5 Posts   394 Views

Avatar
Acidtripchimp

Community Member, 6 Posts

5 April 2012 at 10:26am

Can anybody tell me how to display a list of members from a particular group that have logged in more than once?

I've tried a few things now buy I can only seem to pull members from a group or members that have logged in more than once, can't figure out how to achieve both:

function pullMembers(){

$members = DataObject::get('Member', "NumVisit > 0");
foreach($members as $member){

if ($group = DataObject::get_one("Group", "Title = 'HKmembers'")){

$members->remove($member);

break;

}
}

return $members = $group->Members();
}

Thanks in advanced

Avatar
Willr

Forum Moderator, 5513 Posts

5 April 2012 at 10:53pm

Perhaps something like this

$group = DataObject::get_one("Group", "Title = 'HKmembers'")

$members = DataObject::get('Member', "NumVisit > 0 AND Group_Member.GroupID = '$group->ID'", "", "INNER JOIN Group_Member ON Member.ID = Group_Member.MemberID");

return $members;

Avatar
Acidtripchimp

Community Member, 6 Posts

11 April 2012 at 8:23am

Hi Willr

Thanks very much for the reply.

Having tried this I keep getting a '[User Error] Couldn't run query: SELECT...'

Any idea why that might be?

Using:

function pullMembers(){

$group = DataObject::get_one("Group", "Title = 'HKmembers'");
$members = DataObject::get('Member', "NumVisit > 0 AND Group_Member.GroupID = '$group->ID'", "", "INNER JOIN Group_Member ON Member.ID = Group_Member.MemberID");
return $members;
}
}

Cheers

Matt

Avatar
Willr

Forum Moderator, 5513 Posts

11 April 2012 at 5:58pm

You'll have to post the full error, the first bit isn't much use in most cases :)

I think the issue is the table is actually Group_Members.

$group = DataObject::get_one("Group", "Title = 'HKmembers'");
$members = DataObject::get('Member', "NumVisit > 0 AND Group_Members.GroupID = '$group->ID'", "", "INNER JOIN Group_Members ON Member.ID = Group_Members.MemberID");
return $members;

Avatar
Acidtripchimp

Community Member, 6 Posts

12 April 2012 at 6:39am

Hi Willr

Spot on it was the table, it works fine now.

Thanks for your help!

Matt