RON_ron Posted November 2, 2010 Share Posted November 2, 2010 Assume this project is to create an online lottery system. Is there a way to limit the user entering the numbers after a certain time? E.g. The Draw will be at 9.00PM 05 November 2010 - Submitting the numbers will expire after 8.00PM 05 November 2010. (so any user tries to submit numbers after 8.00PM 05 Nov 2010 will not be entered in to the MySQL db). Any help is highly appreciated. Quote Link to comment Share on other sites More sharing options...
Adam Posted November 2, 2010 Share Posted November 2, 2010 This would fall down to the responsibility of the application, not the database. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 2, 2010 Share Posted November 2, 2010 I agree with MrAdam. I'm assuming you'll be using PHP, so moving thread to PHP Coding help. Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 2, 2010 Share Posted November 2, 2010 You need to determine the draw date/time in the code; then determining if the user is submitting their numbers too close to the draw is very simple. However, since I assume there are going to be multiple draws, you need to decide how you will determine the draw that the person is submitting numbers for. Are you only going to allow them to submit numbers for the next draw or can they submit numbers for any future draw? Anyway, once you have decided on that logic here is how you can test if the submission is x minutes before the draw. You can either get the draw date/time into logical values for hour, minute, second (or just use zero), month, day & year; then use mktime(). Or you can get the date/time of the draw in a string format and use strtotime(); $cutoffTime = 60; //Cutoff in minutes $drawTime = mktime($drawHour, $drawMinute, 0, $drawMonth, $drawDay, $drawYear); //Test if the timestamp (in seconds) for the drawtime minus the //timestamp for NOW (i.e. the number of seconds from now until //the draw) is less than the cutoff time in seconds. if($drawTime-time() < $cutoffTime*60) { //Submission is after the cutoff time // - add error handling } else { //Submission on or before the cutoff time // - allow the submission } Quote Link to comment Share on other sites More sharing options...
RON_ron Posted November 3, 2010 Author Share Posted November 3, 2010 That was very helpful mjdamato!! Thanks. Are you only going to allow them to submit numbers for the next draw or can they submit numbers for any future draw? They can actually submit numbers for the next draw only. Is this how to go about it? $cutoffTime = 44640; //Cutoff set to one month $drawTime = mktime($20, $5, 0, $12, $25, $2010); //8:05PM on 25/12/2010 if($drawTime-time() < $cutoffTime*60) { $sentOk1 = "Expired!."; echo "sentExpired=" .$sentOk1; } else { $query = "INSERT INTO decdraw(name, phone, address, postal, email, number1, number2, number3, number4, number5, number6,) //up to number15, VALUES('$name','$phone','$address','$postal','$email','$number1','$number2','$number3')" // to $number15; $result = mysql_query($query); $sentOk2 = "Your numbers has been added to the database."; echo "sentOk2=" .$sentOk2; } One more question, Can a MySQL handle a lot of entries? or isn't it wise to use MySQL to store the draw numbers + user info? Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 3, 2010 Share Posted November 3, 2010 $cutoffTime = 44640; //Cutoff set to one month So, you are saying that people must submit thier number at least one month prior to the draw? According to your first post I thought the cutoff time was going to be one hour. If you want the cutoff to be a month I would have taken a different approach since a month can be anywhere from 28 to 31 days. I'd probably use strtotime(). $drawTime = mktime($20, $5, 0, $12, $25, $2010); //8:05PM on 25/12/2010 Well, you shouldn't have variable names that begin with numbers, but assuming those variable names are just for illustrative purposes and they would hold the value that is the same as the names, that is correct. And yes MySQL would be fine for holding "a lot" of records. It is a database, that's kind of what it's supposed to do. I'm not saying the code works though, you need to test it. Just set the draw time and the expiration so you have a 5 minute window to submit numbers. Ensure you can submit up until the cutoff and then get the expiration message afterward. Quote Link to comment Share on other sites More sharing options...
RON_ron Posted November 12, 2010 Author Share Posted November 12, 2010 Thanks mjdamato that worked!!! One more question how do I make the time +7 to the time used in strtotime() ? Quote Link to comment Share on other sites More sharing options...
Adam Posted November 12, 2010 Share Posted November 12, 2010 +7 what? Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 12, 2010 Share Posted November 12, 2010 Well, check the manual, that's what it is there for: http://php.net/manual/en/function.strtotime.php If the cutoff time is 7 days before the draw time, here is one possible solution: $drawTime = mktime($20, $5, 0, $12, $25, $2010); //8:05PM on 25/12/2010 if(strtotime('+7 days') > $drawTime) { //Don't allow submission } else { //Allow submission } Quote Link to comment Share on other sites More sharing options...
RON_ron Posted November 15, 2010 Author Share Posted November 15, 2010 I guess I did it. I truly appreciate your help mjdamato!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.