| | |
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 |
.htaccess action ajax apache api array auto beginner binary bounce broken cakephp checkbox class cms code cron curl database date display dynamic echo email error errorlog file files folder form format forms function functions google href htaccess html image include insert integration interactive ip java javascript joomla limit link login loop mail malfunctioning masterthesis menu mlm mod_rewrite multiple mysql nodes oop paypal pdf php popup problem query radio ram random recursion reference regex remote return script search server sessions sms soap source space sql syntax system table tutorial unset update upload url validation validator variable video web websitecontactform xml youtube





