Counting Row By Specific User And Limit!

Discussion in 'PHP' started by canabatz, Nov 21, 2008.

  1. #1
    i need to count the results sent by users ,i need a code to start counting results and find me results from the same user ,i want to be able to limit results by user ,i want to limit the user to maximum 4 rows in a run if it reaches 5 rows the result number 5 will be ignored or something !

    this is the query im using to get my results :

    select * from my table where username=$username and bidprice=$bid_price order by bid_price desc

    like this situation is good:

    user1
    user1
    user1
    user1
    user2 <=there is one result between user1 so its ok
    user1
    user1
    user1

    4 result from user1 then user 2 is between user1 ,user 1 can continue to post more and have 4 rows in a run again!!


    and this way is not good:

    user1
    user1
    user1
    user1
    user1 <===== there is 5 result from user1 so result No. 5 will be deleted
    user2

    thanx
     
    canabatz, Nov 21, 2008 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    add group by userid to your query (userid = the field you want to group)
     
    EricBruggema, Nov 21, 2008 IP
  3. canabatz

    canabatz Greenhorn

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    this is the way i want it to be: [1 is the number of the user in this example]

    1
    1
    1
    1
    2
    1
    1
    1
    1
    2
    1

    there is group of 4 results by user 1 ,thats ok.
    user 1 cannot have groups of 5.

    thanx! :)
     
    canabatz, Nov 21, 2008 IP
  4. canabatz

    canabatz Greenhorn

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #4
    can i have more then one group?
     
    canabatz, Nov 22, 2008 IP