Jump to content

Days based on months


jor133d

Recommended Posts

I am trying to modify some code so that the days dropdown has the correct amount of days for each month( Jan - 31 days, Feb 28, etc). I managed to get it so the correct days appear however it lists all the days.

 

http://www.glitzphotography.com/date/dateform.php

 

Can someone help me get this to work properly?

 

Thanks!

 

<?php 


function make_calendar_pulldowns($m = NULL, $d = NULL, $y = NULL)	// This function makes three pull-down lists
								// for the months, days, and years.
    {

// Make the months array.
$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September',
		      'October', 'November', 'December');

// Make the months pull-down list
echo '<select name="month">';
foreach ($months as $key => $value)
	{
	    echo "<option value=\"$key\"";
	    if ($key == $m) { echo ' selected="selected"'; }
	    echo ">$value</option>\n";
	}
echo '</select>';

// Make the days pull-down list
echo '<select name="day">';

foreach ($months as $key => $value) {

$num = cal_days_in_month(CAL_GREGORIAN, $key, 2007); 

for ($day = 1; $day <= $num; $day++)
	{
	    echo "<option value=\"$day\"";
	    if ($day == $d) { echo ' selected="selected"'; }
	    echo ">$day</option>\n";
	}
}

echo '</select>';

// Make the years pull-down list
echo '<select name="year">';
for ($year = 2005; $year <= 2015; $year++)
	{
	    echo "<option value=\"$year\"";
	    if ($year == $y) { echo ' selected="selected"'; }
	    echo ">$year</option>\n";
	}
echo '</select>';

    } 	// End of the function definition.


// Create the form tags.
echo '<h1 id="mainhead">Select a Date:</h1>
<p><br /></p><form action="dateform.php" method="post">';

// Call the function.
$dates = getdate();
make_calendar_pulldowns($dates['mon'], $dates['mday'], $dates['year']);

// End of form.
echo '</form><p><br /></p>';

// Print the current date and time
echo '<p>Today is ' . date('l') . '. The current time is ' . date('g:i a') . '.</p>';

$num = cal_days_in_month(CAL_GREGORIAN, 11, 2007); // 31
echo "There was $num days";



?>

Link to comment
Share on other sites

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.