943,608 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 1182
  • MySQL RSS
Sep 17th, 2009
0

Limit MySQL Database's Rows

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MArun25039 is offline Offline
7 posts
since May 2009
Sep 17th, 2009
0

Re: Limit MySQL Database's Rows

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.
Reputation Points: 26
Solved Threads: 12
Junior Poster in Training
kylegetson is offline Offline
89 posts
since Sep 2009
Sep 18th, 2009
0

Re: Limit MySQL Database's Rows

Click to Expand / Collapse  Quote originally posted by kylegetson ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MArun25039 is offline Offline
7 posts
since May 2009
Sep 18th, 2009
0

Re: Limit MySQL Database's Rows

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
Reputation Points: 8
Solved Threads: 6
Light Poster
guru12 is offline Offline
44 posts
since Jun 2009
Sep 18th, 2009
0

Re: Limit MySQL Database's Rows

Click to Expand / Collapse  Quote originally posted by MArun25039 ...
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.
Reputation Points: 26
Solved Threads: 12
Junior Poster in Training
kylegetson is offline Offline
89 posts
since Sep 2009
Sep 19th, 2009
0

Re: Limit MySQL Database's Rows

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.
Reputation Points: 485
Solved Threads: 89
Posting Shark
verruckt24 is offline Offline
944 posts
since Nov 2008
Sep 19th, 2009
0

Re: Limit MySQL Database's Rows

Click to Expand / Collapse  Quote originally posted by kylegetson ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MArun25039 is offline Offline
7 posts
since May 2009
Sep 21st, 2009
0

Re: Limit MySQL Database's Rows

yup u look in this site, the best in sql i believe
w3schools.com
Reputation Points: -22
Solved Threads: 4
Junior Poster in Training
vincent2085 is offline Offline
53 posts
since Aug 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: Mysql table name with spaces
Next Thread in MySQL Forum Timeline: 3 letter acroynm





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC