note 54094 deleted from function.date by aidan

From: Date: Sun, 31 Jul 2005 12:33:07 +0000
Subject: note 54094 deleted from function.date by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-92815@lists.php.net to get a copy of this message
Note Submitter: thinsoldier at thinsoldier ,com ---- Because I hate having 50+ lines of html whenever I want to add a day/month/year select box. It allows defining of of name, id, class, width(css), and selected value. So, in my cms when adding a new entry it defaults to the current date and when I'm editing a previous entry it defaults to the date the entry was made (after i explode the mysql date and assign each part to a variable) ----------------------------------------- <p>Function for generating useful date select boxes</p> adding something new, so that's today's date: <br> Day: <? echo $day_box=day_box('list_day', '', '', '155', date("d") ); ?> <br> Month: <? echo $month_box=month_box('list_month', '', '', '155', date("m") ); ?> <br> Year: <? echo $year_box=year_box('list_year', '', '', '100', date("Y") ); ?> <p>Editing something old, so show it's original date pulled from the database or something</p> Day: <? echo $day_box=day_box('list_day', '', '', '155', 14 ); ?> <br> Month: <? echo $month_box=month_box('list_month', '', '', '155', 9 ); ?> <br> Year: <? echo $year_box=year_box('list_year', '', '', '100', 1992 ); ?> <? function day_box($name, $id, $class, $width, $selected) { $content='<select name="'.$name.'" id="'.$id.'" class="'.$class.'" style="width:'.$width.'px">'."\r"; for($i=1; $i<=31; $i++) { if($i == $selected) { $isselected='selected'; } else {$isselected='';} $iki = $i; if($iki<10){$iki='0'.$iki;} $content.="\t<option value=\"$iki\" $isselected>"; $content.="$iki</option>\r"; } $content.="</select>"; return $content; } //////////////////////////////////////// ?> <? function month_box($name, $id, $class, $width, $selected) { $monthtext[1]="January";$monthtext[2]="February"; $monthtext[3]="March";$monthtext[4]="April"; $monthtext[5]="May";$monthtext[6]="June"; $monthtext[7]="July";$monthtext[8]="August"; $monthtext[9]="September";$monthtext[10]="October"; $monthtext[11]="November";$monthtext[12]="December"; $content='<select name="'.$name.'" id="'.$id.'" class="'.$class.'" style="width:'.$width.'px">'."\r"; for($i=1; $i<=12; $i++) { if($i == $selected) { $isselected='selected'; } else {$isselected='';} $iki = $i; if($iki<10){$iki='0'.$iki;} $content.="\t<option value=\"$iki\" $isselected>"; $content.="$iki - $monthtext[$i]</option>\r"; } $content.="</select>"; return $content; } //////////////////////////////////////// ?> <? function year_box($name, $id, $class, $width, $selected) { $content='<select name="'.$name.'" id="'.$id.'" class="'.$class.'" style="width:'.$width.'px">'."\r"; for($i=1990; $i<=2090; $i++) { if($i == $selected) { $isselected='selected'; } else {$isselected='';} $iki = $i; $content.="\t<option value=\"$iki\" $isselected>"; $content.="$iki</option>\r"; } $content.="</select>"; return $content; } //////////////////////////////////////// ?>

« previous php.notes (#92815) next »