Jump to content

d1s0wn3d

New Members
  • Posts

    6
  • Joined

  • Last visited

d1s0wn3d's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Not exactly what I was looking for but can work with it... Thanks Barand!
  2. I'm having a bit of an issue... So what I'm trying to do is this: I have a user table: ------------------------- | Table: userlist | ------------------------- | Id | GuestOf | User | |-----------------------| | 0 | System | Bill | |-----------------------| | 1 | Bill | Jason | |-----------------------| | 2 | Jason | Jack | |-----------------------| | 3 | Jason | Jill | |-----------------------| | 4 | Jack | Matt | |-----------------------| | 5 | Jill | Stu | |-----------------------| | 6 | Jack | Gwen | |-----------------------| | 7 | Jill | Frank | |-----------------------| Details: Jason's guests are Jack and Jill, Jack's guests are Matt and Gwen, and Jill's Guests are Stu and Frank. Now what I want to do is find out if Jason's guests both have their two guests. But I can only check for this each time a new guest is added to the list. In this case, When Frank is inserted. So what should happen is, when Frank gets inserted, I get Jill. Check if she has her 2 guests. Then check who invited her (Jason), check if he has 2 guests, now get the other guest (Jack) and see if he has 2 guests. If they all have their 2 guests each, I should get a value of 7. Which will signal completion of that group of people and guests. When the next person gets inserted, checkCompletion runs again for that insert... This is the code I'm currently using: function countGuests($User) { $sql = "SELECT COUNT(`Id`) CntId FROM `userlist` WHERE `GuestOf` LIKE '$User'"; $res = mysql_query($sql); $temp = mysql_fetch_array($res, MYSQL_BOTH); return $temp["CntId"]; } function checkCompletion($UserId) { $population = array(); $sql = "SELECT `User` FROM `userlist` WHERE `GuestOf` LIKE '$UserId'"; $res = mysql_query($sql); if (mysql_num_rows($res) > 0) { while ($temp = mysql_fetch_array($res, MYSQL_BOTH)) { $population[] = $temp["User"]; } $partialPop = 0; for ($i = 0; $i < count($populaton); ++$i) { $partialPop = $partialPop + countGuests($population[$i]); } } return $partialPop; } Which should give me the result: 7 (Jason, Jack, Jill, Matt, Gwen, Stu, Frank) However, I get the result: 0. What's wrong with my query? I would appreciate any help/corrections... Thank you!
  3. Hi Barand! Sorry for the delayed feedback. I had some personal stuff to attend to. Anyway, your code works perfectly, although, your code doesn't seem to pick-up where it left off. I'm assuming that I should put a check in the while loop to check who the last user was and how many were assigned right? Or should it be done to the assign function? Thanks!
  4. Thanks Barand! I'm going to try this out and report back...
  5. Thanks for replying Barand! Actually, this is what I was describing: +------------+-----+-----+-----+ | player | 1 | 2 | 3 | +------------+-----+-----+-----+ | | 2 | 8 | 16 | | | 3 | 9 | 17 | | | 4 | 10 | 18 | | assigned | 5 | 11 | 19 | | | 6 | 12 | 20 | | | 7 | 13 | 21 | | | | 14 | 22 | | | | 15 | 23 | +------------+-----+-----+-----+ Thanks!
  6. Hi! This'll be my first post... I'm new to PHP so please be gentle. So here's my conundrum: I need to cycle through a list, going back and forth as necessary. What I want to do is, count every x users on the list and "assign" them to the first user in my list. For the second, count every x users, assign them to the second user, etc. After the first user, the value of x will not change. For example: If there are 25 users in the list, then starting with the first user on the list, count the 6 people under him, and "assign" them to him, for the second user, count the 8 users under him but exclude the 6 already assigned to the first user, for the third user, count the 8 users under him but exclude the 6 already assigned to the first user, and the 8 already assigned to the second user, for the fourth user, since the number of users won't equal 8, assign whoever's left and if someone new gets added in the future, pick up from there. I hope I made my point clear... This is my code to get the list: $sql = "SELECT u.* FROM `users` u WHERE u.Active = 1"; $res = Query($sql); if (Rows($res) > 0) { while ($temp = Fetch($res)) { $id = $temp["UserId"]; //Code removed because not relevant } } Thanks!
  7. d1s0wn3d

    Hello!

    Everyone, Hello! I'm new to PHP and MySQL as well. I'm hoping to learn much from hanging out here... Thanks!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.