Jump to content

Recommended Posts

Hi all,

I have an itinerary code that takes the start date and end date from the user and spits out all events happening between those dates.  However, recently, the script won't work properly.  It will work so long as the dates I pick have two characters in them which leads me to believe that it's a formating issue.  What I believe will solve this is if I can find a way, in the drop down menus where it shows the selectable days/months with the leading zeros.  Right now it's "1, 2, 3 .... 9, 10, 11, 12, ..." and I'd like to get it to "01, 02, 03 .... 09, 10, 11, 12, ..."

Here's my code for that section:

[code]
$cur_month = date('m');
$cur_day = date('d');
$cur_year = date('Y');
$total_days = date('t');

$month_start = "<select name=\"start_month\">";
$month_end = "<select name=\"end_month\">";
for ($i=1;$i<=12;$i++)
{
if ($i == $cur_month)
{
$month_start .= "<option value=\"$i\" selected>$i</option>\n";
$month_end .= "<option value=\"$i\" selected>$i</option>\n";
}
else
{
$month_start .= "<option value=\"$i\">$i</option>\n";
$month_end .= "<option value=\"$i\">$i</option>\n";
}
}
$month_start .= "</select>";
$month_end .= "</select>";
[/code]

It's probably something to do with the formating of the FOR loop but I'm just not getting it.  Any ideas?
Link to comment
https://forums.phpfreaks.com/topic/33773-proper-format-for-date-drop-down-menu/
Share on other sites

I can't seem to edit my post. To clarify, that would go:
[code]
for ($i=1;$i<=12;$i++){
  if ($i == $cur_month){
      if($i<10){
        $i = "0".$i;
      }
      $month_start .= "<option value=\"$i\" selected>$i</option>\n";
      $month_end .= "<option value=\"$i\" selected>$i</option>\n";
  }else{
      if($i<10){
        $i = "0".$i;
      }
      $month_start .= "<option value=\"$i\">$i</option>\n";
      $month_end .= "<option value=\"$i\">$i</option>\n";
  }
}
[/code]
[quote author=86Stang link=topic=121971.msg502374#msg502374 date=1168534242]
Can't I mark this as solved?
[/quote]

I believe that they're working on the mod for that now, it needs a few changes since the forum upgrade two days ago.

Regards
Huggie
you should shorten up your code. props to jessi

if ($i == $cur_month){
      if($i<10){
        $i = "0".$i;
      }
      $month_start .= "<option value=\"$i\" selected>$i</option>\n";
      $month_end .= "<option value=\"$i\" selected>$i</option>\n";
  }else{
      if($i<10){
        $i = "0".$i;
      }
      $month_start .= "<option value=\"$i\">$i</option>\n";
      $month_end .= "<option value=\"$i\">$i</option>\n";
  }

to

$selected = ($i == $cur_month) ? 'selected = "selected"' : '';
      if($i<10){
        $i = "0".$i;
      }
      $month_start .= "<option value=\"$i\" $selected >$i</option>\n";
      $month_end .= "<option value=\"$i\" $selected >$i</option>\n";

i used a terany(sp)

(clause) ? if true : if false
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.