offsprg01 Posted February 20, 2007 Share Posted February 20, 2007 here's the code <select name="YEAR" size="1" style="width:100px"> <?php $current_year = date("Y"); do {?> <option value="<?php echo $current_year; ?>" <?php if ($yearText == $current_year) {?> selected="selected"> <?php echo $current_year; ?> </option> <?php } while ($current_year != 2001); ?> </select> am i doing this correctly? i think i am but apparently i'm not. Quote Link to comment https://forums.phpfreaks.com/topic/39266-need-help-with-php-generated-drop-down-list-using-date/ Share on other sites More sharing options...
Jessica Posted February 20, 2007 Share Posted February 20, 2007 It's just selected, not selected="selected". What are you trying to do that isn't working? You never increment the year. This could be accomplished with a slightly shorter for loop. for($i=2001; $i<=date("Y"); $i++){ print '<option value="'.$i.'"'; if($yearText == $i){ print ' selected'; } print '>'.$i.'</option>'; } Quote Link to comment https://forums.phpfreaks.com/topic/39266-need-help-with-php-generated-drop-down-list-using-date/#findComment-189226 Share on other sites More sharing options...
tom100 Posted February 20, 2007 Share Posted February 20, 2007 I actually don't see any incrementing being done, unless I'm missing something. The result would therefore be an infinite loop. You need to incriment it such as jesirose's example. Otherwise you PHP script will timeout. Quote Link to comment https://forums.phpfreaks.com/topic/39266-need-help-with-php-generated-drop-down-list-using-date/#findComment-189228 Share on other sites More sharing options...
offsprg01 Posted February 20, 2007 Author Share Posted February 20, 2007 lol i'm retarded i forgot to incriment currentdate. lol thanks guys. and thanks double for cleaning yup the loop for me jessie. big help Quote Link to comment https://forums.phpfreaks.com/topic/39266-need-help-with-php-generated-drop-down-list-using-date/#findComment-189235 Share on other sites More sharing options...
pixeltrace Posted February 20, 2007 Share Posted February 20, 2007 hi, my problem is also related to this. how about in the case of the days? let say the user selected Jan the day has to change in related to the number of days that jan have what is the code for this? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/39266-need-help-with-php-generated-drop-down-list-using-date/#findComment-189260 Share on other sites More sharing options...
Jessica Posted February 20, 2007 Share Posted February 20, 2007 That would be javascript, and kind of worthless in time. You're going to have to check it serverside anyway with valid_date() (or whatever it is) so just go for 1-31 and give them an error after the fact if they mess with it. Quote Link to comment https://forums.phpfreaks.com/topic/39266-need-help-with-php-generated-drop-down-list-using-date/#findComment-189280 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.