[ciapug] times again

Carl Olsen carl-olsen at mchsi.com
Sun Dec 18 09:47:38 CST 2005


Yes, I do it with three drop downs, and then I validate the input to make
sure it's a valid date.  I put the three drop downs into a user control so
it can be called using a function that accepts a date as the input
parameter.  If the input parameter is null, then it defaults to nothing
selected.  If the input is a date, then it displays that date.  Here's my
code for the user control:

	public function select_date($field, $date = null)
	{
		$selectcontrol = "";
		if ($date == null)
		{
			$curyear = strftime("%Y");
			$curmonth = strftime("%m");
			$curday = strftime("%d");
		}
		else
		{
			$curyear = substr($date, 0, 4);
			$curmonth = substr($date, 5, 2);
			$curday = substr($date, 8, 2);
		}
		$selectcontrol .= "<select id='year_" . $field . "'
name='year_" . $field . "' class='select_year'>";
		if ($stmt = $this->conn->prepare("SELECT syear FROM `year`
ORDER BY syear"))
		{
			$stmt->execute();
			$stmt->bind_result($year);
			$i = 0;
			while($stmt->fetch())
			{
				if ($year == $curyear)
				{
					$selectcontrol .= "<option value='"
. $year . "' selected>" . $year . "</option>";
				}
				else
				{
					$selectcontrol .= "<option value='"
. $year . "'>" . $year . "</option>";
				}
				$i = $i + 1;
			}
			$stmt->close();
		}
		$selectcontrol .= "</select>";
		$selectcontrol .= "<select id='month_" . $field . "'
name='month_" . $field . "' class='select_month'>";
		if ($stmt = $this->conn->prepare("SELECT smonth2,
cabbreviation FROM `month` ORDER BY smonth2"))
		{
			$stmt->execute();
			$stmt->bind_result($month, $abbr);
			$i = 0;
			while($stmt->fetch())
			{
				if ($month == $curmonth)
				{
					$selectcontrol .= "<option value='"
. $month . "' selected>" . $abbr . "</option>";
				}
				else
				{
					$selectcontrol .= "<option value='"
. $month . "'>" . $abbr . "</option>";
				}
				$i = $i + 1;
			}
			$stmt->close();
		}
		$selectcontrol .= "</select>";
		$selectcontrol .= "<select id='day_" . $field . "'
name='day_" . $field . "' class='select_day'>";
		if ($stmt = $this->conn->prepare("SELECT sday FROM `day`
ORDER BY sday"))
		{
			$stmt->execute();
			$stmt->bind_result($day);
			$i = 0;
			while($stmt->fetch())
			{
				if ($day == $curday)
				{
					$selectcontrol .= "<option value='"
. $day . "' selected>" . $day . "</option>";
				}
				else
				{
					$selectcontrol .= "<option value='"
. $day . "'>" . $day . "</option>";
				}
				$i = $i + 1;
			}
			$stmt->close();
		}
		$selectcontrol .= "</select>";
		return $selectcontrol;
	}

-----Original Message-----
From: ciapug-bounces at cialug.org [mailto:ciapug-bounces at cialug.org] On Behalf
Of Dave J. Hala Jr.
Sent: Sunday, December 18, 2005 9:14 AM
To: PHP List
Subject: [ciapug] times again

Anyone doing anything interesting when having users enter a time? For
example: "An end user would enter the time that an event starts".  I'm
thinking maybe a listbox for the hour, one for the minutes and one for
am/pm.   

Anyone have any comments on what works best?

:) Dave
-- 

Open Source Information Systems, Inc. (OSIS)
Dave J. Hala Jr., President <dave at osis.us>
641.485.1606

_______________________________________________
ciapug mailing list
ciapug at cialug.org
http://cialug.org/mailman/listinfo/ciapug



More information about the ciapug mailing list