| | |
Could a switch statement be used here?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2008
Posts: 23
Reputation:
Solved Threads: 0
I've got some code using a lot of complex if statements that I'm using for a VIN decoder. I finally got it working and I'm hesitant to alter it but these if statements are huge! If a switch statement could be used to accomplish what the if statements are doing, could someone give me an example using my data? Here's a snippet of code:
Thanks!
php Syntax (Toggle Plain Text)
$ModelYear=substr($decode,5,1); $AssemblyPlant=strtoupper(substr($decode,6,1)); if ($AssemblyPlant == "2" && ($ModelYear >= 5 && $ModelYear <= 7)){ echo "$AssemblyPlant = St. Therese, Canada<br />"; } elseif ($AssemblyPlant == "7" && $ModelYear == "9"){ echo "$AssemblyPlant = Lordstown, OH<br />"; } elseif ($AssemblyPlant == "B" && $ModelYear == "7"){ echo "$AssemblyPlant = Baltimore, MD<br />"; } elseif ($AssemblyPlant == "C"){ echo "$AssemblyPlant = Southgate, California<br />"; } elseif ($AssemblyPlant == "E" && ($ModelYear >= 6 && $ModelYear <= 9)){ echo "$AssemblyPlant = Linden, NJ<br />"; } elseif ($AssemblyPlant == "G"){ echo "$AssemblyPlant = Framingham, Massachusetts<br />"; } elseif ($AssemblyPlant == "H"){ echo "$AssemblyPlant = Flint, Michigan<br />"; } elseif ($AssemblyPlant == "K" && ($ModelYear >= 5 && $ModelYear <= 7)){ echo "$AssemblyPlant = Leeds, MO<br />"; } elseif ($AssemblyPlant == "L" && ($ModelYear >= 3 && $ModelYear <= 7)){ echo "$AssemblyPlant = Van Nuys, CA<br />"; } elseif ($AssemblyPlant == "N" && $ModelYear == "4"){ echo "$AssemblyPlant = Norwood, OH<br />"; } elseif ($AssemblyPlant == "T" && ($ModelYear >= 6 && $ModelYear <= 9)){ echo "$AssemblyPlant = Tarrytown, NY<br />"; } elseif ($AssemblyPlant == "U" && $ModelYear == "8"){ echo "$AssemblyPlant = Lordstown, OH<br />"; } elseif ($AssemblyPlant == "W" && ($ModelYear >= 8 && $ModelYear <= 9)){ echo "$AssemblyPlant = Willow Run, MI<br />"; } elseif ($AssemblyPlant == "X"){ echo "$AssemblyPlant = Fairfax, Kansas<br />"; } elseif ($AssemblyPlant == "Y" && ($ModelYear >= 2 && $ModelYear <= 5)){ echo "$AssemblyPlant = Wilmington, Delaware<br />"; } elseif ($AssemblyPlant == "Z"){ echo "$AssemblyPlant = Fremont, California<br />"; } else { echo "Buick's weren't built at this plant in 197$ModelYear. Please check your VIN and try again.<br />"; }
Thanks!
Last edited by peter_budo; Jun 10th, 2008 at 7:47 am. Reason: Keep It Organized - please use [code] tags
![]() |
Similar Threads
- switch statement on String in Java (Java)
- C# beginner switch statement (C#)
- switch statement (C)
- Switch Statement, Fall-Through. (C)
- Problems with switch statement (C++)
- Problems with switch statement (C++)
Other Threads in the PHP Forum
- Previous Thread: PHP questions - % of web + finding a developer / host
- Next Thread: pagination within image - IF problem
| Thread Tools | Search this Thread |
ajax apache api array basics beginner binary broken cakephp checkbox class cms code codingproblem combobox cron curl database date display domain dynamic echo email error file files folder form format forms function functions google href htaccess html image include insert interactive ip java javascript joomla js limit link load login mail malfunctioning menu mlm mobile multiple mysql nodes oop outofmemmory paging parse paypal pdf php problem procedure query radio ram random recursion reference remote return script search server sessions sms source space sql syntax system table tutorial unset up-to-date update upload url validation validator variable video web webapplications websitecontactform youtube





