Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End SQL select parent if it has 10+ children

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #165701
    Justin
    Participant

    I am working on a site for a client, and the back end needs to be able to do this:

    Basically if a member obtains 10 of his or her own members, I need to add that user to the top level.

    This gets the top level of members currently (need to add on to this statement)
    select fname, membershipid from dc_tbl_membership WHERE parentid = 0

    This gets the children
    SELECT B.fname, B.middle, B.lname, B.idnumber, A.membershipid AS ParentId, B.membershipid AS ChildId FROM dc_tbl_membership A, dc_tbl_membership B WHERE A.membershipid = B.parentid AND A.membershipid = ‘ . $memid . ‘ ORDER BY A.parentid

    My first thought was to use COUNT, but I am not sure how to use that information to make logical decisions later on..

    Sorry if this is confusing, if you need any more info let me know, I will be watching this topic closely.

    Thanks
    Justin

    #165727
    Justin
    Participant

    Okay great so my first thought was correct, but how would I use that information in the SQL statement?

    #166392
    BionicClick
    Participant

    $myCount = ‘CODE TO DO COUNT AND GET # INTO $myCount variable’;

    then… use your count to determine what to do later…

    if($myCount >= 10) {
    //do work here
    }

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Back End’ is closed to new topics and replies.