steviez Posted May 4, 2010 Share Posted May 4, 2010 Hi, I am making a form to track users earning for the current year and need it to display the months gone all the way up to the current month then auto add each month after that I have searched all over google but cant seem to find any help, anyone got any ideas? Thanks Link to comment https://forums.phpfreaks.com/topic/200619-php-date-help/ Share on other sites More sharing options...
Presto-X Posted May 4, 2010 Share Posted May 4, 2010 Do you mean the rest of the months in this year starting with the current month, or do you mean all of the months up to the current month? Link to comment https://forums.phpfreaks.com/topic/200619-php-date-help/#findComment-1052786 Share on other sites More sharing options...
steviez Posted May 4, 2010 Author Share Posted May 4, 2010 Do you mean the rest of the months in this year starting with the current month, or do you mean all of the months up to the current month? I need it to display all the months that have gone up to the current month, then as we move on a month it adds that too Link to comment https://forums.phpfreaks.com/topic/200619-php-date-help/#findComment-1052787 Share on other sites More sharing options...
Presto-X Posted May 4, 2010 Share Posted May 4, 2010 See if this will work for you: print "<select name='QuoteMonth'>".implode("\n",array_map(create_function('$n','return"<option value=\"$n\"".(date("n")==$n?"selected=\"selected\"":"").">".strftime("%b",strtotime("2004-$n-01"))."</option>";'),range(1,date('m'))))."</select>"; Link to comment https://forums.phpfreaks.com/topic/200619-php-date-help/#findComment-1052792 Share on other sites More sharing options...
steviez Posted May 4, 2010 Author Share Posted May 4, 2010 See if this will work for you: print "<select name='QuoteMonth'>".implode("\n",array_map(create_function('$n','return"<option value=\"$n\"".(date("n")==$n?"selected=\"selected\"":"").">".strftime("%b",strtotime("2004-$n-01"))."</option>";'),range(1,date('m'))))."</select>"; hi, thanks for your help. That seems to work as i need it but how would i get this to work in a html table to display data for each month? Thanks Link to comment https://forums.phpfreaks.com/topic/200619-php-date-help/#findComment-1052795 Share on other sites More sharing options...
Presto-X Posted May 4, 2010 Share Posted May 4, 2010 Would this work? print "<select name=\"month\">"."\n".implode("\n",array_map(create_function('$n','return" <option value=\"".strftime("%b",strtotime("2004-$n-01"))."\"".(date("n")==$n?" selected=\"selected\"":"").">".strftime("%b",strtotime("2004-$n-01"))."</option>";'),range(1,date('m'))))."\n"."</select>"; Link to comment https://forums.phpfreaks.com/topic/200619-php-date-help/#findComment-1052828 Share on other sites More sharing options...
steviez Posted May 4, 2010 Author Share Posted May 4, 2010 Would this work? print "<select name=\"month\">"."\n".implode("\n",array_map(create_function('$n','return" <option value=\"".strftime("%b",strtotime("2004-$n-01"))."\"".(date("n")==$n?" selected=\"selected\"":"").">".strftime("%b",strtotime("2004-$n-01"))."</option>";'),range(1,date('m'))))."\n"."</select>"; thats the same code as above Link to comment https://forums.phpfreaks.com/topic/200619-php-date-help/#findComment-1052917 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.