954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Limit MySQL Database's Rows

Hello,

I'd like to create a basic html form where a user can submit their email address for a cooking class. There would only be room for 20 people so I'd like it to accept the first 20 user and display a "check back next month" to anyone past 20. I'm not having trouble with the form, or entering in to the database, just limiting it to the 20 entries. Can anyone help?

MArun25039
Newbie Poster
7 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

I dont know of a way to actually limit the table to 20 rows, your better off doing a query and conditionally displaying the form. Count the number of entries in the table, then only display the form if there are less than 20 rows.

kylegetson
Junior Poster in Training
89 posts since Sep 2009
Reputation Points: 26
Solved Threads: 12
 
I dont know of a way to actually limit the table to 20 rows, your better off doing a query and conditionally displaying the form. Count the number of entries in the table, then only display the form if there are less than 20 rows.

Unfortunately that will not serve my purpose. I essentially need to set a cap on the number of inquiries I can handle per month. If I understand your suggestion, it only limits the number that will display.

MArun25039
Newbie Poster
7 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

Hello Arun

Steps :

1.Count the row of the table
2.if the row counts less tan 20, condition is true other wise condition is false
example:

Select count(id) From table name where condition
---
execute the query

if($row != 20)
{
condition true
}
else
{
condition false
}

Thanks and Regards

guru12
Light Poster
44 posts since Jun 2009
Reputation Points: 8
Solved Threads: 6
 
Unfortunately that will not serve my purpose. I essentially need to set a cap on the number of inquiries I can handle per month. If I understand your suggestion, it only limits the number that will display.

Im not sure you understood what I meant. I am basically saying to not allow a signup if there are already more than 20 rows. So wherever you print out your form, do a query to check the number of rows this month, or whatever conditions need to be met. If there are already too many, display an friendly error, instead of displaying the HTML form. That way, you could limit your inquiries.

Or, if that won't work, you could always have it email you when it inserts the 20th, and you could manually turn it off, but I think the first suggestion will work.

kylegetson
Junior Poster in Training
89 posts since Sep 2009
Reputation Points: 26
Solved Threads: 12
 

Hi MARUN,

As I see there are some discrepancies in your queries here. First you say that you want to limit the entrants to 20 but then in the second one you say you want to limit the enquiries to 20 so that has me a bit confused over your actual requirements but here's my suggestion from what I have understood, point out if I am wrong.

My suggestion is similar to what kylegetson has offered but it has one critical change, since a web form can be seen by n number of people simultaneously instead of checking the rows prior to generating the form you can generate the form unconditionally and then just check while inserting if the rows are <20, if they aren't you can generate a friendly message informaing them of the event or instead you could also add them to a different table registering them early for the next's months batch and informing them accordingly.

verruckt24
Posting Shark
952 posts since Nov 2008
Reputation Points: 485
Solved Threads: 89
 

Im not sure you understood what I meant. I am basically saying to not allow a signup if there are already more than 20 rows. So wherever you print out your form, do a query to check the number of rows this month, or whatever conditions need to be met. If there are already too many, display an friendly error, instead of displaying the HTML form. That way, you could limit your inquiries.

Or, if that won't work, you could always have it email you when it inserts the 20th, and you could manually turn it off, but I think the first suggestion will work.


Actually your suggestion will work perfectly and most likely the best solution for my situation. I'm sorry I mis-read this the first time, thanks for taking the time to clarify it for me.

MArun25039
Newbie Poster
7 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

yup u look in this site, the best in sql i believe
w3schools.com

vincent2085
Junior Poster in Training
53 posts since Aug 2009
Reputation Points: -22
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You