Jul 25, 2008

Drop Down Lists Using Dates

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Drop Down Lists Using Dates

fsoftball
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!

Reply

palladin
Look at this rolleyes.gif

CODE

<?
// 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 cool.gif

 

 

 


Reply

fsoftball
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 "&nbsp;&nbsp;&nbsp;\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.

Reply

sachavdk
Maybe this is what you want:

CODE
<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

Reply

palladin
Hmm you mean wanna select June as default ?
CODE

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 "&nbsp;&nbsp;&nbsp;\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 cool.gif

Reply

fsoftball
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.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : lists dates

  1. Multiple Drop Down Lists ? - Multiple drop down lists to take user to new page (4)
  2. Converting Dates - converting epoch to MM-DD-YYY (1)
    So this is probably a basic and lame question, but how can I convert dates so I can then sort them?
    Right now, I have each part of a date as a separate variable: $month, $day, $year.
    I'd like to store them in the database as epoch. This way when I do a query I can sort them by
    date. I can figure out the datatype for the database later. I would also need to convert an epoch
    to Month-Day-Year later on when I want to display this. I'm sure this isn't too complicated
    but I figured asking for some suggestions anyway. Thanks!...
  3. Dates - (5)
    Hi, i have users entering a date as a text field. it is simply in ther form: "Apr 4". since it is
    text, i cannot sort and the dates end up out of order. i am guessing that the best way to sort is
    to conveert it to an epoch and sort on that. is there a function to convert this text into a epoch
    date? thanks....



Looking for drop, lists, dates

Searching Video's for drop, lists, dates
advertisement



Drop Down Lists Using Dates



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE