Hello everyone. As some of you may know I am working on building a golf tee time booking system. I have pretty much everything working as of now and it's working great (Thanks DP members ) Anyways, I am on my last hurdle to call it complete. I am submitting names, dates, and times to an sql database. The are done in the format "08052011" for Auguest 5th, 2011 for example. Anyways, my last hurdle is finding a way to book the many leagues the course is home to. I will need to to set start and end times, start and end dates, and what day of the week the league is on. My problem is this: I want to set a start date and an end date. For this example we'll say we are using a Tuesday for the league. I need a way to generate the variables for all Tuesdays between the start and end dates. So if the Start Date is 9/21/2010 and the end date is 11/2/2010, then I need the sql table to look like this when submitted: $date, $time, $name 09212010, 0700, NAME 09282010, 0700, NAME 10052010, 0700, NAME 10122010, 0700, NAME 10192010, 0700, NAME 10262010, 0700, NAME 11022010, 0700, NAME The whole thing here I am searching for is how to "fill in the blanks" for all the dates between the selected start and end date. Any ideas? Would I want to build an array for this somehow?
Easy Well depends if the solution would work for you. What you will need is a starting date and a number of weeks. So then you can build your array like so: $dates = array(); $start_date = strtotime("09/21/2010"); $num_weeks = 7; for ($i = 0; $i < $num_weeks; $i++) { $_date = strtotime("+" . ($i * 1) . " week", $start_date); $dates[] = date ("mdY", $_date); } Code (markup): What this code will do is fill up an array with the dates starting from the start date and incrementing by 1 week each time. Hope that helps you *untested code* aXe
aXe, all I can say is wow. You hit the nail on the head and that works GREAT! I threw it all in a blank php page and did a print_r on the array and that'd be exactly what I need! Thanks for the help!
Hit another "what I think is small" roadblock. I think its just a syntax issue. Here is what I have: $date8 = $_POST['month'].$_POST['day'].$_POST['year']; (This works fine) $start_date = strtotime('$date8'); instead of $start_date = strtotime("09/21/2010"); which was posted above. $date8 is an 8 digit number in MMDDYYYY format.Of everything running, I have verified this to be the problem using print statements to see if the variable was holding data. $start_date is coming up blank when I use the print command. Can someone see the issue in my syntax? I think the problem might be $date8 is in MMDDYYYY format instead of MM/DD/YYYY like aXe's example had- might this be the case? if so how can I convert $date8 to the right format?
That would be it! I put the '/' in with the POST statements, but took out the period there by mistake. Thanks again!