SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ranking Problems

    Okay I have the following code:
    PHP Code:
    $postselect="SELECT *,max(r.postsneeded) as th  FROM b_users u, b_posts p, b_ranks r  WHERE u.posts>= r.postsneeded AND u.userID = p.author and p.ID='$ID'  GROUP BY r.postsneeded"
    Now this work but with one large glaring problem. It displays each method x amount of times based on what rank they are. For instance if they go above 5 posts and achieve the 2nd rank , it will display the message twice, once with the name with the first rank and once with the name a the 2nd rank.

    Can I possibly get it to just display the message once with the highest rank the user has achieved?

  2. #2
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, Now I've got it to this:
    $threadselect="SELECT *,MAX(r.postsneeded) as rankname FROM b_ranks r, b_users u, b_posts p WHERE p.threadparent='$ID' and u.userID = p.author and u.posts>=r.postsneeded GROUP BY p.ID order by p.ID ASC limit $start, 15";
    But when how do I get it to display the corresponding rank? When I display the rank field, it always just displays the first rank.

  3. #3
    SitePoint Wizard Crowe's Avatar
    Join Date
    Nov 2001
    Location
    Huntsville
    Posts
    1,117
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I wouldn't even begin to try to solve this with the sql statement. I would do it with php during the while loop to display your results.

    Just assign $rank as it goes through and the last one will be the only one that sticks.
    Chrispian H. Burks
    Nothing To Say

  4. #4
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, the problem is ranks and users are in two different tables so its hard to compare because the rank field you pull on each iteration of while contains only one rank value.

  5. #5
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Damn, I was trying to do what you suggest but you can only use a query once. You can't pass a query twice.

  6. #6
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still can't get it:
    Say you have:
    PHP Code:
    $result=mysql_query($stuff); 
    You want to pass $result to a function more than once, but you cannot because after the first time, it is empty. I tried mysql_free_result, but it doesn't work. What do I do?

  7. #7
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    mysql_data_seek($result0); 
    will reset a result set back to the beginning.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  8. #8
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your awesome, Jeff!


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
  •