Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: count rows?

  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post

    count rows?

    Okay, this is much harder then I originally thought. I'm trying to display results
    but I want it to get the row 'ref' from members and count the number of members that have the same name under ref and have 'offerscompleted' > 0

    Its pretty hard to explain. But im trying to make a referral contest. Its supposed to show the username, the number of refs that person has that has completed one offer

  • #2
    New Coder
    Join Date
    Aug 2011
    Posts
    51
    Thanks
    6
    Thanked 12 Times in 12 Posts
    Please be more descriptive. I am not sure how your tables are structured, or what it is exactly that you are trying to do.

  • #3
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    It's extremely difficult to explain..

    So lets say a member Member1 signs up at my website under the ref Admin. Lets say this member1 completes an offer so now his offerscompleted > 0 now. The user Admin has just earned one referral towards the contest. How would I make it so it counts the number of members that have the same ref and 1 offer completed?

  • #4
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,424
    Thanks
    70
    Thanked 102 Times in 101 Posts
    PHP Code:
    mysql_query("UPDATE users SET offerscompleted=offerscompleted+1 WHERE ref='Admin' AND member='member1' LIMIT 1"); 
    Change it into variables to select which member gets it.

    or if you want to get the total Admins that have 1 offer point, you'd do this.

    PHP Code:
    $query mysql_query("SELECT * FROM users WHERE ref='Admin' AND offerscompleted > '0'");
    if (
    mysql_num_rows($query) == 0) {
    echo 
    'No Matches';
    }
    else {
    echo 
    'There is matches';

    Last edited by myfayt; 09-05-2011 at 05:25 PM.

  • #5
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    PHP Code:
    $query mysql_query("SELECT * FROM users WHERE ref='Admin' AND offerscompleted > '0'");
    if (
    mysql_num_rows($query) == 0) {
    echo 
    'No Matches';
    }
    else {
    echo 
    'There is matches';

    Right, But that counts only the number of refs the Admin has. What about other members?

  • #6
    New Coder
    Join Date
    Aug 2011
    Posts
    51
    Thanks
    6
    Thanked 12 Times in 12 Posts
    You run the script as you needed on the page that will display the value. If you want to fetch the ref number for all the people at the same time, put that in the while loop under the query SELECT * FROM users... so

  • #7
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,424
    Thanks
    70
    Thanked 102 Times in 101 Posts
    You have to change it into variables for your website, like this.

    PHP Code:
    $query mysql_query("SELECT * FROM users WHERE ref='".$userrow['status']."' AND offerscompleted > '0'");
    if (
    mysql_num_rows($query) == 0) {
    echo 
    'No Matches';
    }
    else {
    echo 
    'There is matches';

    So if your main user row was $userrow, you'd have a field named ref
    and in that field would be like Member, Admin, Guest.

    That would auto load in the query and show you for that ref.

  • #8
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    I'm confused now. What is the
    Code:
    WHERE ref='".$userrow['status']."'
    ????

  • #9
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,424
    Thanks
    70
    Thanked 102 Times in 101 Posts
    status would be whatever the name of the field in your database is, where Admin is under.

  • #10
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    I don't think you quite understand what im trying to accomplish.

  • #11
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,424
    Thanks
    70
    Thanked 102 Times in 101 Posts
    Okay well I've done my best with the little information I had to go on. So if you'd like someone else to look at it, that's okay.

  • #12
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    Quote Originally Posted by markman641 View Post
    I don't think you quite understand what im trying to accomplish.
    your lack of details contributes to the problem. Show a basic layout of your table and an example of the final results. It will be easier to assist you at that point.

  • #13
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    Is really hard to explain.

    I'm trying to count the number of members that have the same name under Ref.

    So if i have 10 members, 3 have Admin under Ref and 2 of them completed an offer. Then there is a member named Animal that has 7 refs and all of them have completed an offer i want it to display that admin has 2 refs and Animal has 7.

  • #14
    New Coder
    Join Date
    Aug 2011
    Posts
    51
    Thanks
    6
    Thanked 12 Times in 12 Posts
    Are you using php in conjunction with your SQL? Could we please see the code that you have so far, maybe it will be clarified what you're trying to do that way.

  • #15
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    I don't have any code so far since I have n clue how to do it. and yes im using php


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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