Jump to content

Need help with php generated drop down list using date()


Recommended Posts

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.

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>';
}

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.