PDA

View Full Version : If, Else Statements - any limits or other solution?



gwmbox
11-26-2009, 01:25 PM
I am trying to have a field auto enter data after a user selects an item from a select list. The select list contains 456 items and the result list is one of 76 items. How best would I do this with php, or should I be using javascript? It will need to update again if the user goes back to the select list and changes it - i.e. recheck the data and re-enter the result into the result field.

Thanks

traq
11-26-2009, 05:34 PM
enter data into what? a database? an email? a subsequent page?

PHP is a fine solution, if the processing is taking place server-side. You could probably use a foreach statement more efficiently than if...else, but we'd have to see your code and know more about what you want to do, exactly.

djr33
11-26-2009, 07:44 PM
You could also try to use switch statements. Basically it's a shorter way to do if/else which just returns a certain value.

http://www.php.net/manual/en/control-structures.switch.php

It's a little weird and only useful in a few situations, but if it applies and you have a lot of data, it can make your list a bit shorter.

JasonDFR
12-06-2009, 08:34 AM
For a list that big, you should use a database.

You'll be able to create the html for the select list with a loop.

Once you have the list item the user selected, then it is just a matter of querying the database to determine which of the 76 result items you need to return.

Hand coding a html select with 476 items must be a nightmare.

djr33
12-06-2009, 09:52 PM
Or a flat file "database" might work.
If you have data and you want to store it and search it, a real database is always the best solution. It also makes it much easier to manage later if you want to expand/upgrade, etc.