Code for Changing YYYY in Dropdown Box.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dwappes
Forum Newbie
Posts: 4
Joined: Sun Jan 31, 2010 3:44 pm

Code for Changing YYYY in Dropdown Box.

Post by dwappes »

I have a PHP string as follows:

selectList( "field_4_YYYY", $_POST["field_4_YYYY"], date("Y")-18, date("Y"), "YYYY", $style ) ;

This (the -18) allows my dropdown box to display the year going back to 1992, which is what I want. However, it also displays all the years to present, as in 2008, 2009 & 2010, which is what I don't want. I only want the available years in the dropdown box to display 1992, 1993, 1994 & 1995.

Can someone please show me what changes need to be made to this string to do that that will automatically update annually? I want the years to always remain at between 15 to 18 years back. Thanks you!
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Code for Changing YYYY in Dropdown Box.

Post by AbraCadaver »

Simple math if I understand your function correctly:

Code: Select all

selectList( "field_4_YYYY", $_POST["field_4_YYYY"], date("Y")-18, date("Y")-15, "YYYY", $style ) ;
Or if that doesn't work, swap them:

Code: Select all

selectList( "field_4_YYYY", $_POST["field_4_YYYY"], date("Y")-15, date("Y")-18, "YYYY", $style ) ;
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
dwappes
Forum Newbie
Posts: 4
Joined: Sun Jan 31, 2010 3:44 pm

Re: Code for Changing YYYY in Dropdown Box.

Post by dwappes »

Thank you.
Post Reply