www.webdeveloper.com
Results 1 to 14 of 14

Thread: if control for array

  1. #1
    Join Date
    Oct 2012
    Location
    istanbul
    Posts
    71

    if control for array

    Hello,

    array post
    Sample:
    form
    Code:
      
      <select size="8" name="day_of_week[]" id="day_of_week" multiple>  
    		<option value="-1" selected="selected">*</option>
    		<option value="0">Sunday</option>
    		<option value="1">Monday</option>
    		<option value="2">Tuesday</option>
    		<option value="3">Wednesday</option>
    		<option value="4">Thursday</option>
    		<option value="5">Friday</option>
    		<option value="6">Saturday</option>		
      </select>
    if(is_array($_POST['day_of_week']) && in_array(GOING TO HAPPEN HERE?, $_POST['day_of_week'])){
    echo "Selected day(s) of week";
    }
    PHP Code:
    if(is_array($_POST['day_of_week']) && in_array(GOING TO HAPPEN HERE?, $_POST['day_of_week'])){
    echo 
    "Selected day(s) of week";
    }


    // this is okay
    if(is_array($_POST['day_of_week']) && in_array('-1'$_POST['day_of_week'])){
    echo 
    "Disabled day(s) of week";

    Thanks
    Last edited by Adem; 09-14-2013 at 09:31 AM.

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    1,904
    What is your question???

  3. #3
    Join Date
    Oct 2012
    Location
    istanbul
    Posts
    71
    Quote Originally Posted by ginerjm View Post
    What is your question???
    I'm sorry, I do not know english

    This question, Selected day of the week
    if(is_array($_POST['day_of_week']) && in_array(GOING TO HAPPEN HERE?, $_POST['day_of_week'])){
    echo "Selected day(s) of week";
    }

  4. #4
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    1,904
    Sorry - don't know what you want to find here.

    Good luck.

  5. #5
    Join Date
    Oct 2012
    Location
    istanbul
    Posts
    71
    Is selected day(s) of the week
    if(??????????){

    }

  6. #6
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    1,904
    Sorry...

  7. #7
    Join Date
    Oct 2012
    Location
    istanbul
    Posts
    71
    Quote Originally Posted by ginerjm View Post
    Sorry...
    Do you have any idea on this subject?
    http://www.webdeveloper.com/forum/sh...s-Can-you-help
    Last edited by Adem; 09-14-2013 at 04:20 PM.

  8. #8
    Join Date
    Mar 2012
    Posts
    3,968
    You need to use the date function. There are a few variations:
    - date('D') returns "Mon" to "Sun".
    - date('l') returns "Monday" to "Sunday".
    - date('N') returns "1" (Monday) to "7" (Sunday).

    So use syntax like:

    if (date('N')=='1') { *** do this for Monday *** }
    elseif (date('N')=='2' { etc... }

    or to test multiple days in a single if statement use STRPOS. However, strpos has a weakness in that matching the first character returns 0, which can be interprted as false instead of true. So you need to either use '===' as in:

    if !(strpos('1357',date('N')) === false) { *** do this if Mon, Wed, Fri or Sun *** }
    else ( *** do this if Tue, Thu or Sat *** }

    or use a dummy character as the first character in the test string that will never match. E.g. Using '_' (underscore) as the first character:

    if (strpos('_1357',date('N')) == true) { *** do this if Mon, Wed, Fri or Sun *** }
    else ( *** do this if Tue, Thu or Sat *** }

    Note: I haven't tested the above code, so it may need tweaking, but this should give you an idea of how to do it.

  9. #9
    Join Date
    Oct 2012
    Location
    istanbul
    Posts
    71
    jedaisoul, Thank you for reply.

    Okay, not the problem
    1....7
    I need the code to control two
    Only if() the code

    array name="day_of_week[]"

    Disable week days, selected(*) value(-1)
    HTML Code:
      <select size="8" name="day_of_week[]" id="day_of_week" multiple>  
            <option value="-1" selected="selected">*</option>
            <option value="1">Sunday</option>
            <option value="2">Monday</option>
            <option value="3">Tuesday</option>
            <option value="4">Wednesday</option>
            <option value="5">Thursday</option>
            <option value="6">Friday</option>
            <option value="7">Saturday</option>        
      </select>
    First control: Disable week days, a selection, a value (-1)
    if($_POST['day_of_week']=='-1'){
    Codes for disable week days
    I have this code available
    }



    Second control: Enable week days, selection a or multi day(s).
    Note: Are excluded * value (-1) "Not select " * " and day(s) of week the same time!"
    // days "1,2,3,4,5,6,7"
    if($_POST['day_of_week']>-1){ // I need some help here
    Codes for aktive week day(s)
    I have this code available
    }



    I've been using it for the dates of the week
    I change the, 1....7, no problem
    and I use this date('N'), no problem
    PHP Code:
                   if($sonraki_gun=='0'){
              
    $h_tarihi=date('d.m.Y'strtotime('noon sunday')); // Pazar
              
    }elseif($sonraki_gun=='1'){
              
    $h_tarihi=date('d.m.Y'strtotime('noon monday')); // Pazartesi
              
    }elseif($sonraki_gun=='2'){
              
    $h_tarihi=date('d.m.Y'strtotime('noon tuesday')); // Salı
              
    }elseif($sonraki_gun=='3'){
              
    $h_tarihi=date('d.m.Y'strtotime('noon wednesday')); // Çarşamba
              
    }elseif($sonraki_gun=='4'){
              
    $h_tarihi=date('d.m.Y'strtotime('noon thursday')); // Perşembe
              
    }elseif($sonraki_gun=='5'){
              
    $h_tarihi=date('d.m.Y'strtotime('noon friday')); // Cuma
              
    }elseif($sonraki_gun=='6'){
              
    $h_tarihi=date('d.m.Y'strtotime('noon saturday')); // Cumartesi
              


    For this project: http://www.zamanlayici.antenfiyati.com/?lng=en
    Last edited by Adem; 09-14-2013 at 07:54 PM.

  10. #10
    Join Date
    Oct 2012
    Location
    istanbul
    Posts
    71
    Sorry, I wrote wrong, fixing it now
    HTML Code:
      <select size="8" name="day_of_week[]" id="day_of_week" multiple>  
    		<option value="-1" selected="selected">*</option>
    		<option value="7">Sunday</option>
    		<option value="1">Monday</option>
    		<option value="2">Tuesday</option>
    		<option value="3">Wednesday</option>
    		<option value="4">Thursday</option>
    		<option value="5">Friday</option>
    		<option value="6">Saturday</option>		
      </select>

  11. #11
    Join Date
    Oct 2012
    Location
    istanbul
    Posts
    71
    Hello,

    True? or False?
    PHP Code:
    $week=array(1,2,3,4,5,6,7);

    // if active days of week
    if(is_array($_POST['day_of_week']) AND array_intersect($week$_POST['day_of_week'])){
    // if active days of week
    }

    // if disable days of week
    if(is_array($_POST['day_of_week']) AND in_array('-1'$_POST['day_of_week'])){
    // if disable days of week


  12. #12
    Join Date
    Mar 2012
    Posts
    3,968
    I've never used arrays as $_POST parameters, so I have no idea whether the code is valid, let alone what it will do. More importantly, I do not understand why you need to pass the day-of-week as an array? You are creating an array, $week, anyway.

    P.S. Shouldn't $week include 0 (not set) as date("N") can return that value for invalid input?

    P.P.S. If you do need to pass info of the "valid" days of the week, I would do so as a string and convert it to an array locally.
    Last edited by jedaisoul; 09-18-2013 at 06:30 AM.

  13. #13
    Join Date
    Oct 2012
    Location
    istanbul
    Posts
    71
    Active week: http://awesomescreenshot.com/0521qgcbaf
    Passive week: http://awesomescreenshot.com/09b1qgco5e
    Required to submit the form
    and
    Only me needed if() control
    PHP Code:
    $week=array(1,2,3,4,5,6,7);

    // if active days of week
    if(is_array($_POST['day_of_week']) AND array_intersect($week$_POST['day_of_week'])){
    // if active days of week
    }

    // if disable days of week
    if(is_array($_POST['day_of_week']) AND in_array('-1'$_POST['day_of_week'])){
    // if disable days of week

    Not the day of the week to determine!

  14. #14
    Join Date
    Mar 2012
    Posts
    3,968
    I do not understand your post, so I cannot offer any assistance.

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.13426 seconds
  • Memory Usage 3,025KB
  • Queries Executed 15 (?)
More Information
Template Usage (36):
  • (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_html
  • (4)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (14)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (14)postbit
  • (14)postbit_onlinestatus
  • (14)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 (72):
  • 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_postinfo_query
  • fetch_postinfo
  • 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