Forum Moderators: coopster

Message Too Old, No Replies

Counting Row By Specific User And Limit!

         

canabatz

9:44 pm on Nov 21, 2008 (gmt 0)

10+ Year Member



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 have 4 result in a row!
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

rob7591

11:32 pm on Nov 21, 2008 (gmt 0)

10+ Year Member




$q = mysql_query($query);
$last_user = '';
$user_count = 0;
while ($row = mysql_fetch_array($q)) {
if ($row['user'] == $last_user)
$user_count++;
else
$user_count = 0;
if ($user_count == 5) {
//Insert code to delete bid
}
$last_user = $row['user']
}

I hope that's what you're looking for

canabatz

10:30 am on Nov 22, 2008 (gmt 0)

10+ Year Member



green is good ,red is bad ,the yellow row is the last inserted row ,so username canabatz got is bid in 5 rows in a row ,and it will deleted or just display a massage!

i hope this time is more good explenation!

thanx for your help!

[edited by: eelixduppy at 6:04 pm (utc) on Nov. 22, 2008]
[edit reason] no screenshots, please [/edit]

canabatz

4:26 pm on Nov 22, 2008 (gmt 0)

10+ Year Member



thanx rob im going to try that! :)

canabatz

9:40 pm on Nov 22, 2008 (gmt 0)

10+ Year Member



Not working :(