WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Select with current month
Categories : PHP, HTML and PHP, Date Time, Arrays Click here to Update Your Picture
Olaf Lederer
Date : Jan 13th 2005
Grade : 2 of 5 (graded 4 times)
Viewed : 8353
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Olaf Lederer
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

This is a simple select element with month notations. You can translate the names for local using. Based on the current date the actual month is selected.

<?php
$curr_month
= date("m");
$month = array (1=>"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$select = "<select name=\"month\">\n";
foreach (
$month as $key => $val) {
   
$select .= "\t<option val=\"".$key."\"";
    if (
$key == $curr_month) {
       
$select .= " selected>".$val."\n";
    } else {
       
$select .= ">".$val."\n";
    }
}
$select .= "</select>";
echo
$select;
?>



Tag content retrieval from websites with preg_match
Categories : PHP, Regexps, Arrays, HTML and PHP
Creates three SELECT form fields: Month, Day, and Year. You give it a string which will be used to make the name for the three fields, and a number of seconds to use as the default date. If you give it blank for this value, the current date is used.
Categories : HTML and PHP, PHP, Date Time
If you want to create select buttons featuring current date this example will show you how...
Categories : Date Time, HTML and PHP, PHP
How to pass an array from one PHP Script to another via an HTML form
Categories : PHP, HTML and PHP, Arrays
dynamic table columns
Categories : PHP, HTML and PHP, Arrays, Databases, MySQL
Website colour changer
Categories : PHP, HTML and PHP, Date Time
Print out array key => value in colored HTML
Categories : PHP, Arrays, HTML and PHP
Form Submission Using Array's
Categories : PHP, HTML and PHP, Beginner Guides, Arrays
CALENDAR - easy calendar-navigation with PHP
Categories : PHP, Date Time, HTML and PHP, Calendar
This script contains 2 functions: 1 to create html select object based on your own customer date format entry- "M d Y h:i.... etc". The second function processes the select object on submit back to unix time.
Categories : PHP, Calendar, Date Time, HTML and PHP
Parsing html tags with php. Get an array from this function
Categories : PHP, HTML and PHP, Arrays, Tag Extractors
Kewl Date Example
Categories : PHP, HTML and PHP, Date Time, CSS, Beginner Guides
Convert date's in YYYY-MM-DD (i.e. mysql format) into PHP3 timestamps. Also Find the difference in days between two PHP3 timestamps.
Categories : HTML and PHP, PHP, MySQL, Date Time
Simple PHP control CSS Calender
Categories : PHP, HTML and PHP, Calendar, Date Time, CSS
enhanced date picker with jcript checking for a dynamic date input
Categories : PHP, Java Script, Date Time, Calendar, Arrays
 James Salinas wrote : 1262
good code, but you can shorten that by doing this:
foreach($month as $key =&gt; $val) {
   $select .= "\t&lt;option val=\"$key\"";
   if($key == $curr_month) {
      $select .= " selected";
   }
   $select .= "&gt;$val\n";
}
*also, to try to keep w3c compliant, should use
$select .= " selected=\"selected\"";
instead ;)
 
 Olaf Lederer wrote :1270
it`s from the w3 website:
&lt;SELECT multiple size="4" name="component-select"&gt;
      &lt;OPTION selected value="Component_1_a"&gt;Component_1&lt;/OPTION&gt;
      &lt;OPTION selected value="Component_1_b"&gt;Component_2&lt;/OPTION&gt;
      &lt;OPTION&gt;Component_3&lt;/OPTION&gt;
      &lt;OPTION&gt;Component_4&lt;/OPTION&gt;
      &lt;OPTION&gt;Component_5&lt;/OPTION&gt;
      &lt;OPTION&gt;Component_6&lt;/OPTION&gt;
      &lt;OPTION&gt;Component_7&lt;/OPTION&gt;
   &lt;/SELECT&gt;

do you know a diff. one?

Olaf