0

I have put this PHP event calendar on my development system. How can I disable adding event on a Saturday or a Sunday? :) Do you think this has to do with this code?

  function dayPullDown($day)
  {
echo "<select name=\"day\">\n";

$selected[$day] = ' selected="selected"';

for($i=1;$i <= 31; $i++) {
    $sel = (isset($selected[$i])) ? $selected[$i] : "";
    echo "  <option value=\"$i\"$sel>$i</option>\n";
}
echo "</select>\n\n";}
chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152
hehehe
  • 1
  • 3
  • 5

1 Answers1

1

Instead of looping through 31 days, you could use PHP's datetime class and check if today is a weekday (not a weekend) and display the dropdown menu only if your condition is satisfied:

$date = new DateTime();
if($date->format('N') < 6) {
    echo "<select name=\"day\">\n";
    $sel = (isset($selected[$i])) ? $selected[$i] : "";
    echo "  <option value=\"$i\"$sel>$i</option>\n";
    echo "</select>\n\n";
}
Amal Murali
  • 75,622
  • 18
  • 128
  • 150
  • where will i put this? – hehehe Sep 25 '13 at 17:33
  • it says undefined i variable – hehehe Sep 25 '13 at 17:48
  • @hehehe: This should go inside your loop. `$i` is defined only in the scope of that loop. – David Sep 25 '13 at 17:50
  • like this? function dayPullDown($day) { echo "\n"; $sel = (isset($selected[$i])) ? $selected[$i] : ""; echo " \n"; } echo "\n\n"; } – hehehe Sep 25 '13 at 17:54