Posted By

gdonald on 09/27/06


Tagged

year options


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

hudge


PHP year options


 / Published in: PHP
 

  1. function getYearOptions( $selected, $offset, $count )
  2. {
  3. $options = '';
  4.  
  5. $start_year = date( 'Y' ) + $offset;
  6.  
  7. $finish_year = $start_year + $count;
  8.  
  9. for( $x = $start_year; $x <= $finish_year; $x++ )
  10. {
  11. if( strlen( $x ) == 1 ) $x = '0' . $x;
  12.  
  13. $options .= '<option value="' . $x . '"';
  14.  
  15. if( $x == $selected )
  16. {
  17. $options .= ' selected="selected"';
  18. }
  19.  
  20. $options .= '>' . $x . '</option>';
  21. }
  22.  
  23. return $options;
  24. }

Report this snippet  

You need to login to post a comment.