We help IT Professionals succeed at work.
Get Started

Eliminate duplication here

Colin Brazier
on
69 Views
Last Modified: 2019-12-05
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;
}

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2020
Most Valuable Expert 2018
Commented:
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE