Obvious duplication here, just because I need an ascending date range in one, and descending in the other. But I can't think how to do it with one version only.
function DateDropDown($startdays,$size,$DateDropName,$SatSun) { // $startdays = for results, we start at present day (0), for fixtures, we start at next week(7). // $size = the number of days to display in the drop down echo "<select class='formSelect' id='$DateDropName' name='$DateDropName' >\n"; for ($i = $startdays; [b]$i >= $size; $i--[/b]) { $theday = mktime (0,0,0,date("m") ,date("d")+$i ,date("Y")); $option=date("D M j, Y",$theday); $value=date("Y-m-d",$theday); echo "<option value=\"$value\">$option</option>\n"; } echo "</select>\n"; return;}function DateDropDownFix($startdays,$size,$DateDropName,$SatSun) { // $startdays = for results, we start at present day (0), for fixtures, we start at next week(7). // $size = the number of days to display in the drop down echo "<select class='formSelect' id='$DateDropName' name='$DateDropName' >\n"; for ($i = $startdays; [b]$i <= $size; $i++[/b]) { $theday = mktime (0,0,0,date("m") ,date("d")+$i ,date("Y")); $option=date("D M j, Y",$theday); $value=date("Y-m-d",$theday); echo "<option value=\"$value\">$option</option>\n"; } echo "</select>\n"; return;}
It creates a range for your days to add to the date and the extra argument $desc determines how that range is sorted, and in which order the days are added to the day.
function DateDropDown($startdays,$size,$DateDropName,$SatSun, $desc=True) { // $startdays = for results, we start at present day (0), for fixtures, we start at next week(7). // $size = the number of days to display in the drop down $days = range($startdays, $startdays+$size); if($desc){ rsort($days); } echo "<select class='formSelect' id='$DateDropName' name='$DateDropName' >\n"; foreach($days as $i) { $theday = mktime (0,0,0,date("m") ,date("d")+$i ,date("Y")); $option=date("D M j, Y",$theday); $value=date("Y-m-d",$theday); echo "<option value=\"$value\">$option</option>\n"; } echo "</select>\n"; return;}
Function call: DateDropDown(0,8,"Dropdown","SatSun", False);
Output:
<select class='formSelect' id='Dropdown' name='Dropdown' ><option value="2019-12-04">Wed Dec 4, 2019</option><option value="2019-12-05">Thu Dec 5, 2019</option><option value="2019-12-06">Fri Dec 6, 2019</option><option value="2019-12-07">Sat Dec 7, 2019</option><option value="2019-12-08">Sun Dec 8, 2019</option><option value="2019-12-09">Mon Dec 9, 2019</option><option value="2019-12-10">Tue Dec 10, 2019</option><option value="2019-12-11">Wed Dec 11, 2019</option><option value="2019-12-12">Thu Dec 12, 2019</option></select>
Function call: DateDropDown(0,8,"DropDown","SatSun", True); Output:
<select class='formSelect' id='DropDown' name='DropDown' ><option value="2019-12-12">Thu Dec 12, 2019</option><option value="2019-12-11">Wed Dec 11, 2019</option><option value="2019-12-10">Tue Dec 10, 2019</option><option value="2019-12-09">Mon Dec 9, 2019</option><option value="2019-12-08">Sun Dec 8, 2019</option><option value="2019-12-07">Sat Dec 7, 2019</option><option value="2019-12-06">Fri Dec 6, 2019</option><option value="2019-12-05">Thu Dec 5, 2019</option><option value="2019-12-04">Wed Dec 4, 2019</option></select>
No worries. Output buffering is a nice way to build strings for return using the output functions (echo / printf etc). I tend to find it's a cleaner way of handling it rather than trying to concatenate strings into a variable.
It creates a range for your days to add to the date and the extra argument $desc determines how that range is sorted, and in which order the days are added to the day.
Open in new window
Here's some sample output.
Function call: DateDropDown(0,8,"Dropdown
Output:
Open in new window
Function call: DateDropDown(0,8,"DropDown
Output:
Open in new window