Echo only if two variables are true

Reply

Join Date: Jun 2008
Posts: 23
Reputation: forwardlookguy is an unknown quantity at this point 
Solved Threads: 0
forwardlookguy forwardlookguy is offline Offline
Newbie Poster

Echo only if two variables are true

 
0
  #1
Jun 5th, 2008
I've hit a new road block on my VIN decoder page. I want to echo something only if two variables are true.

Here's what I want to do:

if (($Series == "D") && ($ModelYear == "2")){
echo "Skylark";
} else {
echo "This is not a valid Series";
}
When I type 4D27H2H111111 into the decoder, it yields the else statement. I have defined the two variables $Series (the D in the above VIN) and $ModelYear (the 2 in the above VIN) and I want to echo "Skylark" only if those two variables are true. For instance, if the VIN was changed to 4D27H4H111111, it would echo the else statement.

Thanks for the help,
Arthur Ash III
Last edited by forwardlookguy; Jun 5th, 2008 at 2:50 pm. Reason: posted before finishing thread
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 61
Reputation: TommyBs is an unknown quantity at this point 
Solved Threads: 11
TommyBs's Avatar
TommyBs TommyBs is offline Offline
Junior Poster in Training

Re: Echo only if two variables are true

 
0
  #2
Jun 5th, 2008
Have you tried echoing out $series and $modelyear in the else statement so you can double check they are being set correctly and its not a problem with the decoder?
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,403
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 224
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: Echo only if two variables are true

 
0
  #3
Jun 5th, 2008
You have the statement correct but you don't need those extra parenthesis
  1. if ($Series == "D" && $ModelYear == "2"){
  2. echo "Skylark";
  3. } else {
  4. echo "This is not a valid Series";
  5. }
That should work just fine, I'm not entirely sure what the problem is.
Last edited by ShawnCplus; Jun 5th, 2008 at 4:59 pm.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 23
Reputation: forwardlookguy is an unknown quantity at this point 
Solved Threads: 0
forwardlookguy forwardlookguy is offline Offline
Newbie Poster

Re: Echo only if two variables are true

 
0
  #4
Jun 6th, 2008
When I echo out that statement in the else statement, nothing shows up. Likewise, when I take away that second set of parenthesis, nothing shows up. In fact, skips over that set of if-else statements altogether and echoes the next set. I'm stumped! Here's my code. I'm going to use switch statements in the future. I'm just trying to get this figured out first.

<?php

$decode=$_POST['VIN'];

$Make=substr($decode,0,1);
if ($Make == "4"){
echo "Buick<br />";
} else {
echo "This is not a valid Make";
}

$Series=strtoupper(substr($decode,1,1));

if ($Series == "D" && $ModelYear == "2"){
echo "Skylark";
} elseif ($Series == "F"){
echo "Sport Wagon";
} elseif ($Series == "G"){
echo "GS";
} elseif ($Series == "H"){
echo "Skylark Custom";
} elseif ($Series == "L"){
echo "Lesabre";
} elseif ($Series == "N"){
echo "Lesabre Custom";
} elseif ($Series == "P"){
echo "Centurion";
} elseif ($Series == "R"){
echo "Estate Wagon";
} elseif ($Series == "U"){
echo "Electra 225";
} elseif ($Series == "V"){
echo "Electra 225 Custom";
} elseif ($Series == "Y"){
echo "Riviera";
} else {
echo "This is not a valid Body Style";
}

$BodyStyle=substr($decode,2,2);
if ($BodyStyle == "27"){
echo "2-door Coupe";
} elseif ($BodyStyle == "35"){
echo "2-seat Station Wagon";
} elseif ($BodyStyle == "36"){
echo "2-seat Sport Wagon";
} elseif ($BodyStyle == "37"){
echo "2-door Hardtop";
} elseif ($BodyStyle == "39"){
echo "4-door Hardtop";
} elseif ($BodyStyle == "45"){
echo "3-seat Station Wagon";
} elseif ($BodyStyle == "47"){
echo "2-door Hardtop";
} elseif ($BodyStyle == "57"){
echo "2-door Hardtop";
} elseif ($BodyStyle == "67"){
echo "2-door Convertible";
} elseif ($BodyStyle == "69"){
echo "4-door Sedan";
} elseif ($BodyStyle == "87"){
echo "2-door Hardtop";
} else {
echo "This is not a valid Body Style";

}

$Engine=strtoupper(substr($decode,4,1));
if ($Engine == "G"){
echo "350 1-2bbl. Dual Exhaust";
} elseif ($Engine == "H"){
echo "350 1-2bbl.";
} elseif ($Engine == "J"){
echo "350 1-4bbl.";
} elseif ($Engine == "K"){
echo "350 1-4bbl. Dual Exhaust";
} elseif ($Engine == "T"){
echo "455 1-4bbl.";
} elseif ($Engine == "U"){
echo "455 1-4bbl. Dual Exhaust";
} elseif ($Engine == "V"){
echo "455 1-4bbl. Stage 1";
} elseif ($Engine == "W"){
echo "455 1-4bbl. Stage 1";
} else {
echo "This is not a valid Engine";
}

$ModelYear=substr($decode,5,1);
if ($ModelYear == "2"){
echo "197$ModelYear";
}else{
echo "This is not a valid Model Year";
}

$AssemblyPlant=strtoupper(substr($decode,6,1));
if ($AssemblyPlant == "C"){
echo "Southgate, California";
} elseif ($AssemblyPlant == "G"){
echo "Framingham, Massachusetts";
} elseif ($AssemblyPlant == "H"){
echo "Flint, Michigan";
} elseif ($AssemblyPlant == "X"){
echo "Fairfax, Kansas";
} elseif ($AssemblyPlant == "Y"){
echo "Wilmington, Delaware";
} elseif ($AssemblyPlant == "Z"){
echo "Fremont, California";
}else{
echo "This is not a valid Assembly Plant";
}

$ProductionNumber=substr($decode,7,6);
if (is_numeric($ProductionNumber)){
echo $ProductionNumber - 100001;
}else {
echo "This is not a valid Production Number";
}

?>
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,403
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 224
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: Echo only if two variables are true

 
0
  #5
Jun 6th, 2008
This is the perfect situation for a switch statement. PHP can use a switch statement on strings unlike C.
  1. switch($Series){
  2. case "A":
  3. do_something;
  4. break;
  5. default:
  6. case "D":
  7. do_something_else;
  8. break;
  9. }
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 23
Reputation: forwardlookguy is an unknown quantity at this point 
Solved Threads: 0
forwardlookguy forwardlookguy is offline Offline
Newbie Poster

Re: Echo only if two variables are true

 
0
  #6
Jun 6th, 2008
Well, I tried using a switch statement but I'm stuck again. I have this so far:

switch ($Series)
{
case ($Series == "D" && $ModelYear == "2"):
echo "Skylark";
break;

case ($Series == "D" && $ModelYear == "3"):

echo "Century";
default:
echo "This is not a valid Body Style";
break;
}

That's not working. Can you even have something like that for the cases? This is what I'm trying to accomplish: In 1972, D stood for Skylark. In 1973, the D was changed to stand for Century. When the user inputs data, I'm wanting the code to use the model year to determine what the D stands for. Can this be accomplished with a switch statement or even an if statement?

Thanks,
Arthur Ash III
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,403
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 224
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: Echo only if two variables are true

 
0
  #7
Jun 6th, 2008
Go take a look at how switch statements work, they aren't if statements.
  1. switch($Series){
  2. case 'A': // equivalent to if($Series == 'A')
  3. do_something();
  4. break;
  5. default: // default handles what happens if none of the cases are true
  6. case 'B': // equivalent to else if($Series == 'B')
  7. do_something_else();
  8. break;
  9. }
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 23
Reputation: forwardlookguy is an unknown quantity at this point 
Solved Threads: 0
forwardlookguy forwardlookguy is offline Offline
Newbie Poster

Re: Echo only if two variables are true

 
0
  #8
Jun 6th, 2008
I know how they work but the example you posted still isn't doing what I'm trying to accomplish. If a user was to input 4A27H2H111111, then what you posted would echo something for A. Whereas, if the user input 4B27H2H111111 it would echo something for B. I'm pretty sure that's what you are saying. But what I'm trying to do is use the year code (the 2 in between the H's) to determine what the switch statement outputs. That's why I had "case ($Series == "D" && $ModelYear == "2"):" for the first case because I wanted D to echo Skylark if and only if the $ModelYear was "2". It's clear in my head what I want but maybe it's not coming across that way...

I appreciate you help and patience though Shawn!

Thanks,
Arthur
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 252
Reputation: ProfessorPC is an unknown quantity at this point 
Solved Threads: 27
ProfessorPC ProfessorPC is offline Offline
Posting Whiz in Training

Re: Echo only if two variables are true

 
0
  #9
Jun 6th, 2008
just looking but dont you want to set the model year to the value between the H's?
  1. $ModelYear=substr($decode,5,1);
  2. switch ($ModelYear){
  3. Case 0:
  4.  
  5. break;
  6. Case 1:
  7.  
  8. break;
  9. Case 2: //Display Skylark
  10. echo "Skylark";
  11. break;
  12. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 23
Reputation: forwardlookguy is an unknown quantity at this point 
Solved Threads: 0
forwardlookguy forwardlookguy is offline Offline
Newbie Poster

Re: Echo only if two variables are true

 
0
  #10
Jun 6th, 2008
Thanks for the reply. That wouldn't work for what I'm trying to do either. I only want "Skylark" to display if $Series == "D" && $ModelYear == "2". I'm just looking for a way to incorporate that into my code. I'm not sure if a switch statement or an if statement would accomplish this. From what I've seen, you can't put something like that into a case for a switch statement. Am I wrong? Is there something better to accomplish my goal?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC