year select
Hi I have the below code that putt to year in the past into a select option.
I want two years in the past, the current year and two years in the future to be offered in the select menu and I want the current year to be the default value
any idea how to make the changes
PHP Code:
<?php
$thisYear = date ( 'Y' );
$yearsN = range ( $thisYear - 2 , $thisYear );
$yearsN = array_reverse ( $yearsN );
foreach( array_reverse ( $yearsN ) as $value )
{
echo '<option ' ;
if( $value == $year )
{
echo " selected='selected'" ;
}
echo "> $value </option>\n" ;
}
?>
Kevin
I think this is what you're looking for (untested):
PHP Code:
<?php
$thisYear = date ( 'Y' );
$yearsN = range ( $thisYear - 2 , $thisYear + 2 );
$yearsN = array_reverse ( $yearsN );
foreach( array_reverse ( $yearsN ) as $value )
{
echo '<option ' ;
if( $value == $thisYear )
{
echo " selected='selected'" ;
}
echo "> $value </option>\n" ;
}
?>
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in
Nation
eBookworm.us
thank you, that did the trick
Kevin
how do I set the value for each potion equal to the year
I trie dthe below but no luck
PHP Code:
<?php
$thisYear = date ( 'Y' );
$yearsN = range ( $thisYear - 2 , $thisYear + 2 );
$yearsN = array_reverse ( $yearsN );
foreach( array_reverse ( $yearsN ) as $value )
{
echo '<option value =' . $yearsN ;
if( $value == $thisYear )
{
echo " selected='selected'" ;
}
echo "> $value </option>\n" ;
}
?>
Kevin
u r missing the quote in the value
that y it not selecting the value for the year
if u look at it carefully
PHP Code:
<?php
$thisYear = date ( 'Y' );
$yearsN = range ( $thisYear - 2 , $thisYear + 2 );
echo '<select name="year">' ;
foreach( $yearsN as $value ) {
echo '<option value="' . $value . '"' ;
if( $value == $thisYear ) {
echo ' selected="selected' ;
}
echo "\"> $value </option>\n" ;
}
echo '</select>' ;
?>
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks