Jump to:

22993 Posts in 11829 Topics by 2827 members

General Questions

SilverStripe Forums » General Questions » Members in a group that have logged in more than once

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

Page: 1
Go to End
Author Topic: 307 Views
  • Acidtripchimp
    Avatar
    Community Member
    6 Posts

    Members in a group that have logged in more than once Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Members in a group that have logged in more than once Link to this post

    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;

  • Acidtripchimp
    Avatar
    Community Member
    6 Posts

    Re: Members in a group that have logged in more than once Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Members in a group that have logged in more than once Link to this post

    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;

  • Acidtripchimp
    Avatar
    Community Member
    6 Posts

    Re: Members in a group that have logged in more than once Link to this post

    Hi Willr

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

    Thanks for your help!

    Matt

    307 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.