Jul 4, 2009

Php Counting Row By Specific User And Limit!

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > PHP Programming

Php Counting Row By Specific User And Limit!

canabatz
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:
SQL
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!!
CODE
user1
user1
user1
user1
user2 <===== there is one result between user1 so its ok
user1

and this way is not good:
CODE
user1
user1
user1
user1
user1 <===== there is 5 result from user1 so result No. 5 will be deleted
user2

thanx

 

 

 


Comment/Reply (w/o sign-up)

truefusion
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.

Comment/Reply (w/o sign-up)

shadowx
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....:

CODE
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) > 4
get 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 DB
END IF

add 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.

 

 

 


Comment/Reply (w/o sign-up)

canabatz
Hello , thanx for your replay smile.gif

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:
CODE
$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 !! smile.gif

Comment/Reply (w/o sign-up)

truefusion
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.

Comment/Reply (w/o sign-up)

canabatz
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!

Comment/Reply (w/o sign-up)

truefusion
QUOTE(canabatz @ Nov 21 2008, 04:41 AM) *
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.

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : php, counting, row, specific, user, limit

  1. Unexpected T_string In User.php [resolved]
    (5)
  2. How Would I Go About Making A Simple "counting" Script?
    (3)
    I plan on making a script for basic voting between different options, and I'd like to know what
    PHP coding I would require. Basically, each choice will be as simple as this: CODE Best
    falsetto? Person A Person B What PHP would be used to basically add 1 value to a
    specified .txt file based on which option is chosen? (Like, if person A was selected, it would add 1
    to persona.txt, and if person B was chosen, it would add 1 to personb.txt) Thanks in advance to
    whoever helps. I'm not good at this kind of intermediate/advanced PHP. /ph34r.gi....
  3. Php Ftp Upload Form
    Adding User Directory to PHP Upload Form - Help (1)
    Alright I am trying to have a PHP FTP Upload Form that allows the user to create the directory
    folder for where they want to upload there files to. example: Main Directory: vainsoft.com There
    directory: vainsoft.com/modeling or vainsoft.com/photography But I dont want them to be able to
    upload things into the main directory, only sub-directories, is that possible with this coding that
    I have: //uses $_FILES global array //see manual for older PHP version info //This function
    will be used to get the extension from the filename function get_extension($file,$length....
  4. Counting Variables?
    (4)
    Write a php script that will accept a positive integer, if it is even, divide it by 2 and if it is
    odd, multiply it by 3 and add 1. Repeat the process until the value is 1, printing out each value.
    Finally print out how many of these operations you performed. If the input value is less than 1,
    print error and perform an exit(); For example: Initial value: 9 Next value: 28 Next value: 14
    Next value: 7 Next value: 22 Next value: 11 Next value: 34 Next value: 17 Next value: 52 Next
    value: 26 Next value: 13 Next value: 40 Next value: 20 Next value: 10 Next value: 5 Nex....
  5. [mysql]get Id Of Loged In User?
    (7)
    how to get the id number of the loged in user? my db is id. username. password. i have tryed a
    few things.. but i never seem to get it right /ohmy.gif" style="vertical-align:middle" emoid=":o"
    border="0" alt="ohmy.gif" />....
  6. Compare 2 List Of User Ids From Different Tables
    (1)
    Hi all. I am trying to make a list out of 2 list. The first list is a complete list of users id
    from users table (List A) The Second list is of users id from another table (List /cool.gif"
    style="vertical-align:middle" emoid="B)" border="0" alt="cool.gif" /> I want to subtrack the user
    ids in List B from List A and make List C. Thanks in advance for any help /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Update: I looked up a old
    sql book i had and found some query examples. I tried the EXCEPT statement in mysql but it dont wor....
  7. Multiple Drop Down Lists ?
    Multiple drop down lists to take user to new page (4)
    Hi everyone I was wondering if anyone could help. I want to create a page with multiple drop down
    lists and depending what the user selects decides the page they will be taken to. Sorry i havent
    explained this too well. Here is an example of what i want (link below) the user is also emailed a
    copy http://www.dermalogica.com/SpeedMappingOnl...US®ion=B I have searched the web and come
    close but nothing does it right I would be extremely greatful if anyone could help! Thanks ....
  8. Directing To A User To Specific Page First Time Only
    (3)
    I make a signup page. I want that when someone signups and login for first time..then he is directed
    to the page X automatically. but after that it is redirected to Page Y always... Its pretty simple
    thing to do but im not understanding how i can make the script to identify that a person has logged
    in for first time ... anyhelp would be so welcome. Thanks.....
  9. Replace A Character In A Specific Tag
    (7)
    I need a code that replaces all spaces between ] brackets with an underscore. So, basically, I
    write this into a variable: CODE bla bla something ] more text here And I want a script to
    change it to this: CODE bla bla something ] more text here Any suggestions?....
  10. Script That Tracks The User Status
    how can I track on or offline users? (4)
    long explaination: hey, I'm building a user profile site right now. And, I kinda know how to
    make a online/offline detector, but not totally sure. I know I can make a mysql database to track
    them, but how does it entrer the information? I could easily put in a field where when they login it
    sets them to online, but if they don't sign out, and just exit the browser, how can I tell.
    short: I want someone to tell me how to make a online/offline status detector, like they have here
    on trap17. I'd be thrilled if you can post to this, thanks, arcticsnpr....
  11. Password Strength / User Availablity Scripts ?
    (2)
    many of u guys would already have noticed that now a days , on most of the websites , when some one
    sign in...as he puts his desired username in the textbox , the page shows that it is not available
    or it is available...without pushing any button etc.. and the second thing , when some one writes
    the password , on the same screen , it shows that password is weak or password is strong... i think
    it is done with php ... can some one give me a link to any page where i can access these scripts ?
    or some one can help me regarding this ?? Thanks for helping always.....
  12. How To Read Specific Row From Table
    according where no=xx (5)
    For example... a table have 2 columns, 100 rows for column i.e. no, name I want to get
    corresponding name when no=17 How to write this php coding??....
  13. Cleaning User Input With Regex
    (1)
    As anyone who works with user input knows, not everyone who submits information makes it look
    proper. One one of my web forms, I parse all the needed fields that I wish to be title cased; their
    name, address, city, etc. I use this to perform this action, which works nicely: PHP Code: CODE
    $string = ucwords(strtolower($string)); This fixes the input if the user types in all caps
    or all lowercase. There is a problem I have been noticing about those who enter a generation after
    their name, such as "Bill Warner III". The above function changes it to "Bill Warn....
  14. Counting Characters Of Textarea...
    (3)
    good day webmasters... i am in need of a script that will count the inputted characters one will
    enter... i mean the script must count the number of characters in a textarea as i am entering
    characters to the textarea.. i know the logic but i cant translate it yet in PHP... so i hope you
    can help me... thanks a lot in advance... /blink.gif' border='0' style='vertical-align:middle'
    alt='blink.gif' /> ....
  15. User Login System With Setcookies
    (13)
    a friend of mine is quite good at php and told me not to use sessions and to use setcookie im not
    sure how to use setcookie to make a user authentication system and was wondering if anyone here know
    a tutorial on how to do it....
  16. Create A Windows User Account
    (1)
    hi, i am making an online registration scheme for my website for some webspace. i have got every
    thing sorted out exsept for one thing. to acces the ftp service and upload files to there user space
    i need to create a user account on the server for that user. is there a way to create a user account
    on a windows operating system with php 5 installed. thanks, kvarnerexpress ....
  17. Php Login Script
    Removing the login field once the user logs in (18)
    Hey everyone. I have a login script that i know works. My question is that on my main page, it have
    a form to allow the user to log in. What i want it to do is that once the user logs in, the form
    disappears and the users data (aka username) is displayed where the form was. At the moment i cant
    get it to work. Below is my code. CODE      if ($logged_in == 1)    {  ?>          
    }//if     else     {  ?>     " method="post">         Username:            
    Password:                     }//else ?> What happens....
  18. User Log-in
    PHP question (2)
    Hello all, I am a PHP n00b. I have read the Login page post, which is over my head. I was hoping
    someone could explain a concept to me more in layman's terms. This is what I hope to do - I want
    to go to my url (www.xyzblah.com) and have it automatically prompt for either a username and
    password, or just a password. After the correct credentials are supplied, go to the regular
    index.html. Any help you could give me is appreciated. Thanks.....

    1. Looking for php, counting, row, specific, user, limit

Searching Video's for php, counting, row, specific, user, limit
See Also,
advertisement


Php Counting Row By Specific User And Limit!

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com