Wrox Programmer Forums
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 6th, 2004, 05:37 AM
Authorized User
 
Join Date: Oct 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default date problem

i would like to let user enter their date of birth by providing list box for them to choose the year, month and date but i don't know how. So, i end up with the following code with is very long and uneffective. And for example, February only has 28/ 29 days but the user may choose 30 and 31 with my code.Is there a better way? Please provide me with the code. Thx.

D.O.B (yy, mm, day) <?php
           echo " <select name=\"empDOByear\" tabindex=\"6\" id=\"textbox\">";
            for($i=gmdate("Y"); $i>=1900 ; $i--)
            {
                echo "<option value=\"$i\" >$i </option>";
            }
            echo " </select>";
        ?>
        <select name="empDOBmonth" tabindex="7" id="textbox2">";
            <option value="01" >01</option>
            <option value="02" >02</option>
            <option value="03" >03</option>
            <option value="04" >04</option>
            <option value="05" >05</option>
            <option value="06" >06</option>
            <option value="07" >07</option>
            <option value="08" >08</option>
            <option value="09" >09</option>
            <option value="10">10</option>
            <option value="11">11</option>
            <option value="12">12</option>
        </select>
        <?php
        echo " <select name=\"empDOBday\" tabindex=\"8\" id=\"textbox3\">";
            for($i=1; $i<=31; $i++)
            {
                echo "<option value=\"$i\" >$i </option>";
            }
            echo " </select>";
        ?><br><br>

Besides, if at another page i display the value of date retrieved from a query, how did i select the retrieved value while displaying other as well values to let the user update or change the data ?

 
Old March 10th, 2004, 05:09 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

I would suggest using JavaScript to dynamically add/remove days based on the month selection.

PHP could do this for you but you'd have a more complicated program.

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old May 26th, 2004, 11:12 AM
Authorized User
 
Join Date: Oct 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default


PHP can do it for you. Use this piece of code to get number of days of the selected month of the selected year (you might want to make the form to submit to itself first as the user selects a year and a month) :

<PHP>

$n_days_of_month = date("t", mktime(0,0,0, $month, date(d), $year));

</PHP>

which make your for loop became:
<PHP>
for($i=1; $i<=$n_days_of_month; $i++)
{
   echo "<option value=\"$i\" >$i </option>";
}
</PHP>

Hope that give you an idea... :)


« Wayang Mßeling »
÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ ÷÷÷÷÷
ASP Newbie needs guidances here





Similar Threads
Thread Thread Starter Forum Replies Last Post
DATE PROBLEM ricespn Classic ASP Basics 3 October 20th, 2006 07:15 AM
Date Problem kuku SQL Server 2000 4 September 7th, 2005 08:38 PM
Date Problem. rupen Classic ASP Basics 3 June 3rd, 2005 09:58 AM
Date Problem tdaustin Classic ASP Basics 10 August 13th, 2004 01:43 PM
Date problem Larson VB How-To 2 December 30th, 2003 06:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.