www.webdeveloper.com
Results 1 to 3 of 3

Thread: PHP - Drop down

  1. #1
    Join Date
    Sep 2012
    Posts
    7

    PHP - Drop down

    Hi

    I have one date field drop down :


    PHP Code:
    $day $_POST['day'];
    $mon $_POST['month'];
    $year $_POST['year'];
    $dob $year "-" $mon "-" $day;
    $ins = array(
    'd_dob' => $dob
    ); 


    PHP Code:
    <tr>
                        <td align="left" valign="middle">Date Of Birth<span class="astrikrequired">*</span>: </td>
                        <td align="left" valign="middle">
                        <select name="day" id="day" class="tyextfild validate-selection required">
                                <?php
                                    
    if($day == '')
                                    {
                                        
    $day=date(dstrtotime($d_dob));
                                    }
                                    
    $gnrl->getDropdownList(array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31'),$day);
                                    
    ?>
                        </select>
                        <select name="month" id="month" class="tyextfild validate-selection required">
                            <?php
                                
    if($month == '')
                                    {
                                        
    $month=date(mstrtotime($d_dob));
                                        
                                    }
                            
    ?>
                                  <option value="01" <?php if(in_array('01',explode(',',$month))) echo 'selected="selected"';?> >Jan</option>
                                  <option value="02" <?php if(in_array('02',explode(',',$month))) echo 'selected="selected"';?>>Feb</option>
                                  <option value="03" <?php if(in_array('03',explode(',',$month))) echo 'selected="selected"';?>>Mar</option>
                                  <option value="04" <?php if(in_array('04',explode(',',$month))) echo 'selected="selected"';?>>Apr</option>
                                  <option value="05" <?php if(in_array('05',explode(',',$month))) echo 'selected="selected"';?>>May</option>
                                  <option value="06" <?php if(in_array('06',explode(',',$month))) echo 'selected="selected"';?>>Jun</option>
                                  <option value="07" <?php if(in_array('07',explode(',',$month))) echo 'selected="selected"';?>>Jul</option>
                                  <option value="08" <?php if(in_array('08',explode(',',$month))) echo 'selected="selected"';?>>Aug</option>
                                  <option value="09" <?php if(in_array('09',explode(',',$month))) echo 'selected="selected"';?>>Sep</option>
                                  <option value="10" <?php if(in_array('10',explode(',',$month))) echo 'selected="selected"';?>>Oct</option>
                                  <option value="11" <?php if(in_array('11',explode(',',$month))) echo 'selected="selected"';?>>Nov</option>
                                  <option value="12" <?php if(in_array('12',explode(',',$month))) echo 'selected="selected"';?>>Dec</option>
                        </select>        
                        <select name="year" id="year" class="tyextfild validate-selection required">
                                <?php
                                    
    if($year == '')
                                    {
                                        
    $year=date(Ystrtotime($d_dob));
                                    }
                                    
    $gnrl->getDropdownList(array('1960','1961','1962','1963','1964','1965','1966','1967','1968','1969','1970','1971','1972','1973','1974','1975','1976','1977','1978','1979','1980','1981','1982','1983','1984','1985','1986','1987','1988','1989','1990','1991','1992','1993','1994','1995','1996','1997','1998','1999','2000','2001','2002','2003','2004','2005','2006','2007','2008','2009','2010','2011','2012'),$year);
                                
    ?>

                    </select>
                        </td>
                      </tr>


    This works perfectly. After i select date/month/year,and submit, its showing the results stored in the db without any issues... now i need another date set same thing like this. for ex date/month/year drop down. i tried changing the variable names etc but still it shows incorrect date/month/year (previous data) can help me how can i create another set of this 3 dorp down without issues?

    Thanks

  2. #2
    Join Date
    Mar 2012
    Posts
    21
    dont know what you mean, but here is some cleaner code anyway

    Code:
    <select name="day" id="day" class="tyextfild validate-selection required">
                                <?php
                                    if($day == '')
                                    {
                                        $day=date(d, strtotime($d_dob));
                                    }
                                    $gnrl->getDropdownList(range( 1, 31 ),$day);
                                    ?>
                        </select>
                        
                        <select name="month" id="month" class="tyextfild validate-selection required">
                            <?php
                                if($month == '')
                                    {
                                        $month=date(m, strtotime($d_dob));
                                        
                                    }
    
                                    for($i=00; $i <= 12; $i++ ) {
    
    	                                $selected = ( in_array('$i',explode(',',$month) ) ? "selected=\"selected\"" : "" );
    
                                  		echo "<option value=\"$i\"$selected>". date(M, $i) ."</option>";
     
                                    }
     
                                    if($year == '')
                                    {
                                        $year=date(Y, strtotime($d_dob));
                                    }
                                    $gnrl->getDropdownList(range( '1970', date( 'Y', time() ) ),$year);
                                ?>
    
                    </select>
    Last edited by n0x; 09-08-2012 at 09:00 PM.

  3. #3
    Join Date
    Sep 2012
    Posts
    7
    Thanks but what about year dropdown?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.33403 seconds
  • Memory Usage 2,901KB
  • Queries Executed 13 (?)
More Information
Template Usage (34):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_code
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (3)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates