SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict LiveTronix's Avatar
    Join Date
    Sep 2001
    Location
    Vancouver
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Threaded Discussion Complex Query Help

    Okay --

    I am trying to limit the number of queries I hit the database with -- so rather than running a PHP loop I want to write on more complex SQL.

    Thread table
    -> ThreadID
    -> ParentThreadID (can be unlimited levels deep)
    -> more rows that don't matter

    GroupPermission
    -> GroupPermissionID
    -> ThreadID
    -> IntranetGroupID
    -> Level (0 - No Accress, 1 - Read, 2 - Write, 3 - Write & Manage)

    IntranetGroup
    -> IntranetGroupID
    -> GroupName

    So permissions are inherit. So say there is thread structure like this.

    Thread Records
    ID - Name - ParentThreadID
    1 - Home - 0
    2 - Sub of "Home" - 1
    3 - Sub of "Sub of Home" - 2

    GroupPermissionRecords
    ID - ThreadID - IntranetGroupID - Level

    1 - 1 - 1 - 3

    IntranetGroup
    ID - GroupName

    1 - Example

    So permissions are inherit so any user in Example group should have "Write & Manage" permission to Home, Sub of Home, and Sub of Sub of Home.

    I want to do 1 single sql query that shows any user who can see Sub of Sub of Home. Since it's not necessarly registered to a particular thread ID it's hard to do this with one query.

    I do this twice -- once for specific users and once for groups so if I save a lot of queries for Groups, I will save them for Users too.

    Is this possible? Any help would be appreciated.

    Thanks in advance.

  2. #2
    SitePoint Addict LiveTronix's Avatar
    Join Date
    Sep 2001
    Location
    Vancouver
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still looking for some help. If anyone needs more of an explanation let me know.

  3. #3
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  4. #4
    SitePoint Addict LiveTronix's Avatar
    Join Date
    Sep 2001
    Location
    Vancouver
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, that article was very useful as I was struggeling through getting that working...

    Got to be an SQL solution to the above problem?

  5. #5
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Basically, you're trying to find all of parents of given node. With adjacency model you've choosen it's impossible to write one single query for this, you'll need loops / recursion. Nested sets or paths model would be the better choice.

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by LiveTronix
    Got to be an SQL solution to the above problem?
    there might indeed be

    my problem, however, is that i can't understand your problem

    "I want to do 1 single sql query that shows any user who can see Sub of Sub of Home"

    "sub of sub of home" has Thread id=3, so that part's easy, but what's a user? i don't see a user table
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •