Results 1 to 5 of 5

Thread: Limit to number of Else Ifs? Too Much Recursion

  1. #1
    Join Date
    Jul 2009

    Limit to number of Else Ifs? Too Much Recursion

    Hey, I am really inexperienced with javascript and am coming up with this error that I do not know how to fix.

    Here is what I'm trying to do. I have a database table full of a couple thousand people with unique ids and on a web page form people have the ability to edit one person at a time. To do so, I want them to enter in the persons id# to identify which person it is since this avoids the problems of incorrect spelling of the persons name, people that have the same name, ect.

    What I wanted to do with javascript is check to see what number they have entered in the input text area then check to see if it matches a record in the database, if so output the name so they know they have the correct id or tell them the id is not valid.

    Since I'm inexperienced with javascript and know of no way to have the javascript query my database the only way I knew how to do this is to dynamically create a javascript function with the server side language I'm using (PHP) that contains a long if-else if-else if...and so on for every unique id. However, when I try to run this it doesn't work and firebug gives the error that there is too much recursion and the function is no longer recognized. I had the script only return the first few results and it worked so I was puzzled. I kept upping the number of unique ids it would show and therefore the number of else if statements and I got it to work for up to 1,535 of them and it runs fast even when entering id 1535. But, for 1536 it doesn't work.

    Looking at the else if statement generated by id 1536 there is nothing special about it. It is valid like all the rest, and its body doesn't call another function, it just returns the name.

    I know there is probably a better way to do this, but I find this to be a peculiar error and was hoping someone could give me some insights.


  2. #2
    Join Date
    Jan 2009
    What if you just used ajax to pass the ID to your php script that looks up the user. Then php can call the SQL and return the name if a name is returned or return false if they don't exist. You wouldn't need a bunch of if-then-else statements at the point and you could let the SQL do the work like its built to do.

  3. #3
    Join Date
    Jul 2009
    Yes, I figured ajax would be able to do it by querying the database but I have never used ajax and don't know how.

    This is probably a good time to learn it I guess, but I still am curious about the error.

  4. #4
    Join Date
    Jan 2009
    I can't help you with the error without seeing your code. I'm having trouble understanding why you have so many if-then-else statements in the first place. If you only wanted to load the db into javascript when the page loads initially you should use an array and just check if the index exists and thus you would again only have a singe if-then-else block to work with.

  5. #5
    Join Date
    Jul 2009
    i am a newbie when it comes to JavaScript, but if you have more then three conditions switch is a better option... i dont know about its limits thou but you could test it out... here is how it would look:
                 switch  (mode)  {                              //mode been the variable
    			case "height":                       //if the variable mode == height
    				document.write.('height');  //code to execute if height
    					 break;            //break required at end of each case
    			case "width":
    			case "both":
                             default:                                     //if the variable is not equal to any of the options
                                      document.write.('no match');

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.33076 seconds
  • Memory Usage 2,884KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (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
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (5)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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