Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Programming Help > PHP Programming Help

PHP Programming Help Post any question relating to PHP Programming here and hopefully someone can help.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2004-07-19, 02:22 PM
sckar
Guest
 
Posts: n/a
Default

Hello,

I am new to PHP and I am having trouble with this. I created a simple page that has a form. There's 3 list fields.

First Field has Dates, so I filled the information like this:
<tr>
<td>Day:</td><td>
<select name="day">
<option>1</option>
<option>2</option>....
<option>31</option>

For the month field the same thing:
<tr>
<td>Month:</td><td>
<select name="month">
<option>Jan</option> ...

and the same for the year. I was wondering what I can do to make the default values in the three fields to point to the current date. Day-> 19, month -> July and year 2004, instead of a weird defualt value. Thanks
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2004-07-19, 02:41 PM
Guest
Guest
 
Posts: n/a
Default

$current = explode("-", date("M-d", time()));
$day = $current[1];
$month = $current[0];

Now just do an if statement when parsing through the options. If it == then make it selected.
Reply With Quote
  #3 (permalink)  
Old 2004-07-19, 03:02 PM
Member
 
Join Date: Apr 2004
Location: Gresham, Oregon. United States
Posts: 46
CYBER_Aeon
Default

Here you go:

Code:
 $Current = explode( "-", date( "n-j-Y" ) );

 $Month = $Current[0];
 $Day = $Current[1];
 $Year = $Current[2];
 
 $FirstYear = 1980;
 $LastYear = $Year; Â*// Only display up to the current year - Change if you need
 
 // Output Days
 echo "<TR><TD>Day:</TD><TD><SELECT NAME='day'>\n";
 for( $i = 1; $i <= 31; $i++ )
 {
 Â* Â*echo "<OPTION VALUE='" . $i . "'";
 Â* Â*if ( $i == $Day ) echo " SELECTED";
 Â* Â*echo ">" . $i . "</OPTION>\n";
 }
 echo "</SELECT></TD</TR>\n";

 // Output Months
 echo "<TR><TD>Month:</TD><TD><SELECT NAME='month'>\n";
 for( $i = 1; $i <= 12; $i++ )
 {
 Â* Â*echo "<OPTION";
 Â* Â*if ( $i == $Month ) echo " SELECTED";
 Â* Â*echo ">" . date( "M", mktime( 0, 0, 0, $i, $Day, $Year ) ) . "</OPTION>\n";
 }
 echo "</SELECT></TD</TR>\n";

 // Output Years
 echo "<TR><TD>Year:</TD><TD><SELECT NAME='year'>\n";
 for( $i = $FirstYear; $i <= $LastYear; $i++ )
 {
 Â* Â*echo "<OPTION VALUE='" . $i . "'";
 Â* Â*if ( $i == $Year ) echo " SELECTED";
 Â* Â*echo ">" . $i . "</OPTION>\n";
 }
 echo "</SELECT></TD</TR>\n";
That'll do it - I even tested it.

If you want to see it in action, click here.
Reply With Quote
  #4 (permalink)  
Old 2004-07-19, 03:40 PM
sckar
Guest
 
Posts: n/a
Default

Thank you very much CYBER_Aeon.
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 10:52 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.