note 54094 added to function.date

From: Date: Thu, 23 Jun 2005 14:08:07 +0000
Subject: note 54094 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-90841@lists.php.net to get a copy of this message
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; } //////////////////////////////////////// ?> ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54094 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54094&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54094&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54094&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54094&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54094&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54094&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54094&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#90841) next »