Jump to content
xisto Community
Sign in to follow this  
fsoftball

Drop Down Lists Using Dates

Recommended Posts

Hi,I have a page where the user enters a date. I would like to use drop down boxes for the date. I would like the current date to be the default date. I think that part is pretty easy. However, I am having trouble listing all of the months. It wills tart at July and end at December. I need to list January through June. Anyone know a good way to list all the months? I am assuming that I will be able to do the same sort of thing for the date.Thanks!

Share this post


Link to post
Share on other sites

Look at this :P

<?// Months Start Here$month[0]="--";$month[1]="January";$month[2]="February";$month[3]="March";$month[4]="April";$month[5]="May";$month[6]="June";$month[7]="July";$month[8]="August";$month[9]="September";$month[10]="Octobre";$month[11]="November";$month[12]="December";// End Months Start Here// Days Start Here$days[0]="Sun";$days[1]="Mon";$days[2]="Tues";$days[3]="Wed";$days[4]="Thu";$days[5]="Fri";$days[6]="Sat";// End Days Start Here//Add Month Func.$dayno=(int)date("w");// End Add Month Func.//Add Month Func.$monno=(int)date("m");// End Add Month Func.// Show date on the page.echo $days[$dayno]." ".$month[$monno]." ".date("d")."/".date("Y");// End Show date on the page.?>


--------------------

Practice is when evrything is work but no one know why.
Theory is when work nothing but evry one know why.
Programmers join Practice with Theory - nothing work and no one know why B)

Share this post


Link to post
Share on other sites

Thanks palladin. While that is helpful, it isn't really what I'm looking.Here is a snip of the code I currently use:echo "<SELECT name='month'>\n";echo "<option value ='Apr'>April</option>\n";echo "<option value ='May'>May</option>\n";echo "<option value ='June'>June</option>\n";echo "<option value ='July'>July</option>\n";echo "<option value ='August'>August</option>\n";echo "</select>\n";echo "   \n";I want 'June' to be the top month displayed, but I do not want to loose 'Apr' and 'May'. This might be an html question rather than a PHP question.

Share this post


Link to post
Share on other sites

Maybe this is what you want:

<html><body><select name="datum"><?$date = getdate();for ($i=$date[0];$i<=($date[0]+31536000);$i+=86400){	echo "<option value=\"".date("Y/d/m H:i:s",$i)."\">".date("Y/d/m H:i:s",$i)."</option>";}?></select></body></html>

the list orders the dates from the day the list is called (ie when you're testing the script) until today next year. if you don't want today next year to be listed use in the code instead of 31536000 this number: 31449600.
The date is written in the format YYYY/DD/MM HH:MM:SS (year/day/month hour:minute:second). You can change it if you want. If you want to use other look here http://be.php.net/manual/en/function.date.php.
You only have to change the formatting "Y/d/m H:i:s" to ie "d/m/Y" but remember with this script you have to do it twice. Once for the value and once for the one that is written in de dropdownlist.

If anything doesn't work like you want please ask

Share this post


Link to post
Share on other sites

Hmm you mean wanna select June as default ?

echo "<SELECT name='month'>\n";echo "<option value ='Apr'>April</option>\n";echo "<option value ='May'>May</option>\n";echo "<option [B]selected[/B] value ='June'>June</option>\n";echo "<option value ='July'>July</option>\n";echo "<option value ='August'>August</option>\n";echo "</select>\n";echo "   \n";

Use selected after otpion and combo box will set a June as default without touching them.


--------------------

Practice is when evrything is work but no one know why.
Theory is when work nothing but evry one know why.
Programmers join Practice with Theory - nothing work and no one know why :P

Share this post


Link to post
Share on other sites

That is what I'm looking for palladin. But I can' seem to get it to to work. do I need eto do somethingmore thatn simply add the selected to that option?

 

When I do it, shouldn't that month be displayed in the drop down menu?

 

Thanks again.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.