Updating member's birthday: month value does not show up right

5 posts by 3 authors in: Forums > CMS Builder
Last Post: November 20, 2012   (RSS)

By hiroko - November 17, 2012

Hi,
I am working with the date value for members to fill in their birthday.
I was able to find the code in the forum, but the month shows up as the current month 12 times in the pull down.
Like this:
November
November
November
November
November
November
November
November
November
November
November
November

Month:
<select name="month">
<?php foreach(range(1,12) as $month): ?>
<option value="<?php echo $month;?> <?php selectedIf($month,@$_REQUEST['month']);?>"><?php echo date("F",strtotime("0000-$month"));?></option>
<?php endforeach ?>
</select>


It works fine and I can update the records if I write like this :
Month:
<select name="month">
<?php foreach(range(1,12) as $month): ?>
<option value="<?php echo $month;?> <?php selectedIf($month,@$_REQUEST['month']);?>"><?php echo $month;?></option>
<?php endforeach ?>
</select>


Of course this only shows the numbers of the month. It's not a big problem for now, but it would be better to show up as January, February... and I am wondering why this is happening.

Thanks

Hiroko

Re: [gkornbluth] Updating member's birthday: month value does not show up right

Hi Hiroko,

In certain versions of PHP you can't leave any parts of a date string as 0 when using the strtotime function. Try changing the code to look something like this:

<select name="month">
<?php foreach(range(1,12) as $month): ?>
<option value="<?php echo $month;?> <?php selectedIf($month,@$_REQUEST['month']);?>"><?php echo date("F",strtotime("1985-$month-01 00:00:00"));?></option>
<?php endforeach ?>
</select>


You can use whatever year and day of the month you like, as long as the $month variable stays the same.

Let me know if this doesn't work for you.

Thanks!
Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] Updating member's birthday: month value does not show up right

Hi Greg,

Thanks for another new bit of information.

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [greg] Updating member's birthday: month value does not show up right

By hiroko - November 20, 2012

Greg,

Thank you, this worked perfect!

hiroko