Jump to content
xisto Community
Sign in to follow this  
canabatz

Php Counting Row By Specific User And Limit!

Recommended Posts

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 deleted or something !

this is my example code fo geting the results:

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


like this situation is good: 4 result from the same user then user 2 is between ,the result 5 from user 1 ,user 1 can continue to post more and have 4 rows in a run again!!

user1user1user1user1user2 <===== there is one result between user1 so its okuser1
and this way is not good:
user1user1user1user1user1 <===== there is 5 result from user1 so result No. 5 will be deleteduser2
thanx

Share this post


Link to post
Share on other sites

Though i don't entirely understand what you're trying to do, but if i understand anything, why not just keep track of how many times a user "sent a result", and if it equals 4, disable the user until another user does the same act the previous user committed? This seems simpler than your method of what appears to be the same thing that is being achieved. And this way you don't have to delete anything, and most likely don't even have to create new rows to keep track of results.

Share this post


Link to post
Share on other sites

truefusion's idea is a good one, if, everytime a user submits data, your submission script checks the DB for that user's name, then count the rows returned. If it is above 4 either reject the user and tell them they cant submit any more data, or delete the last result (presumably the one that is bottom of the result set) and then add your new result to the database....:

EVENT: User "user01" clicks "submit" button to sent data to the submission script and eventually to the database...--submission script:connect to database...$rows = return the ID of all rows where username="user01"IF numrows($rows) > 4get the last result ID (order the result set from the query in reverse order, then get the ID of the FIRST key in the array)delete that row from the DBEND IFadd the user's information to the database

Obviously that isnt real code, its a skeleton of the processes i would go through to solve the issue.

Share this post


Link to post
Share on other sites

Hello , thanx for your replay :)

im running auction site that the user with the highest unique bid wins ,now i want to put limit on user bids on the first 50 result from the auction!!

i want it to be like that!!

any user will have maximum 9 bids in first 50 results ,bid 10 will be burned(deleted or something)

user can have 4 bids in a row it can be like that for example ( bid 10,11,12,13 or 21,22,23,24)
user cannot have bids like that (2,3,4,5,6 or 10,11,12,13,14 )

user can have only group of 4 result ,group of 5 results the last bid that is between the 4 results will be deleted!!

i hope you got me better now!!

i try this code but it's limiting the user to maximum 5 bids from the total 0f 50 bids:

$query = mysql_query("SELECT * FROM `bidding_details` where bid_id=$bid_id and username='$username' order by bid_price desc limit 50") or die(mysql_error());   $username==$last;   $last = 1;  $count = 0;  	while ($line = mysql_fetch_array($query))  {   	if ($last == $line['username'])   	 { 	$count++;  	 } 	else  	 {  	 $last = 0;  	 $count = 0;  	 }   	if ($count > 4)  	 	 {   	  	 header("location:product_detailframe.php?msg=11&&bid_id=$bid_id"); 	 exit;	 	 } 	  }

any help will be very very helpful !! :)

Share this post


Link to post
Share on other sites

To be more specific on what i meant, my concept does not require any rows to be created or deleted for the desired result. At most it may require a new column or two to be inserted in the users' table, where you would keep track of how many times the user "sent a result." If there is a need to keep track of what was submitted, then two columns: one an "integer" for the number of times the user submitted something, and one, i suppose, "text" for what was submitted, since i have no idea what can be submitted. Think of it similar to PHP's argv and argc variables.

Share this post


Link to post
Share on other sites

i dont think i need to insert more two columns ,i need the a code to do like thatstart the counting from the query.if found username1 start counting if found 4 rows from username1 ,delete the last inserted bid from current user or whatever!if found less then 4 rows ,go to next user and count rows!then again go to next user ,or again if it is username1 ,start counting!!all that in a loop!!tahnx!

Edited by canabatz (see edit history)

Share this post


Link to post
Share on other sites

i dont think i need to insert more two columns ,i need the a code to do like that
start the counting from the query.
if found username1 start counting
if found 4 rows from username1 ,delete the last inserted bid from current user or whatever!
if found less then 4 rows ,go to next user and count rows!

then again go to next user ,or again if it is username1 ,start counting!!

all that in a loop!!
tahnx!

The easiest way i can think of to get the desired result you want is if for the active auction you grab the last three bids before you do anything with the submitted bid. Assuming the result is within an array, you pull out all the usernames from the result, and if the user that is trying to bid again is found three times within the result, deny the bid. This means that you won't need to delete anything and can have a complete bidding history of the active auction while achieving the task you want to accomplish. This also seems like less work for the server.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.