This topic is locked

If Statement Help

10/2/2008 1:31:33 PM
PHPRunner General questions
U
Urnso author

I have several location that will use my app. They will all have the option to check multiple boxes.
let say the user checks material issue but they are in Texas. I need just the email to go to texas not Ohio or other places.
material Field
Branches field (consists of 4 places) it's a drop down box on the form.
This code works for one location:
[codebox]If($values["Material_Issue"] == True){

$email="you@who.com";

$message="";

$subject="Cleveland - Root Cause Entry for Material Issue";

foreach($values as $field=>$value)

$message.= $field." : ".$value."\r\n";

mail($email, $subject, $message);
}[/codebox]
I tried this for multiple locations and couldn't get it to work:
[codebox]If($values["Material_Issue"] == True){

} elseif($values["Branches"] == "Ohio"){

$email="you@who.com";

$message="";

$subject="Ohio - Root Cause Entry for Material Issue";

foreach($values as $field=>$value)

$message.= $field." : ".$value."\r\n";

mail($email, $subject, $message);

} elseif($values["Branches"] == "Texas"){

$email="you@who.com";

$message="";

$subject="Texas - Root Cause Entry for Material Issue";

foreach($values as $field=>$value)

$message.= $field." : ".$value."\r\n";

mail($email, $subject, $message);
}[/codebox]
Hope someone can help me with this one. Thx!

T
thesofa 10/2/2008

I have several location that will use my app. They will all have the option to check multiple boxes.

let say the user checks material issue but they are in Texas. I need just the email to go to texas not Ohio or other places.
material Field
Branches field (consists of 4 places) it's a drop down box on the form.
This code works for one location:
[codebox]If($values["Material_Issue"] == True){

$email="you@who.com";

$message="";

$subject="Cleveland - Root Cause Entry for Material Issue";

foreach($values as $field=>$value)

$message.= $field." : ".$value."\r\n";

mail($email, $subject, $message);
}[/codebox]
I tried this for multiple locations and couldn't get it to work:
[codebox]If($values["Material_Issue"] == True){

} elseif($values["Branches"] == "Ohio"){

$email="you@who.com";

$message="";

$subject="Ohio - Root Cause Entry for Material Issue";

foreach($values as $field=>$value)

$message.= $field." : ".$value."\r\n";

mail($email, $subject, $message);

} elseif($values["Branches"] == "Texas"){

$email="you@who.com";

$message="";

$subject="Texas - Root Cause Entry for Material Issue";

foreach($values as $field=>$value)

$message.= $field." : ".$value."\r\n";

mail($email, $subject, $message);
}[/codebox]
Hope someone can help me with this one. Thx!



you could use one piece of code for the whole thing maybe, how about

[codebox]

If($values["Material_Issue"] == True)

{

$branch=$values["Branches"] ;

$email="you@who.com";

$message="";

$subject=$branch." - Root Cause Entry for Material Issue";

foreach($values as $field=>$value)

$message.= $field." : ".$value."\r\n";

mail($email, $subject, $message);
}[/codebox]
Do you think that this is worth a try, then if you need to expand the list of locations as your application becomes world wide, all you do is add locations to the branches table!

HTH

U
Urnso author 10/2/2008

That could work. I would need to make another table for the email addresses too (multiple branches = multiple emails). Plus another query to get the data. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=33618&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />
I am used to Access where you can do a If a = this AND b = this Then do something.
Is there nothing like that in PHP?
Sorry I meant to change it for different emails.
[codebox]If($values["Material_Issue"] == True){

} elseif($values["Branches"] == "Ohio"){

$email="John@who.com";

$message="";

$subject="Ohio - Root Cause Entry for Material Issue";

foreach($values as $field=>$value)

$message.= $field." : ".$value."\r\n";

mail($email, $subject, $message);

} elseif($values["Branches"] == "Texas"){

$email="Tom@who.com";

$message="";

$subject="Texas - Root Cause Entry for Material Issue";

foreach($values as $field=>$value)

$message.= $field." : ".$value."\r\n";

mail($email, $subject, $message);
}[/codebox]

T
thesofa 10/2/2008
If($values["Material_Issue"] == True)

{

$branch=$values["Branches"];

$email="you@who.com";

$message="";

$subject=$branch." - Root Cause Entry for Material Issue";

foreach($values as $field=>$value)

$message.= $field." : ".$value."\r\n";

mail($email, $subject, $message);
}



will still work if you have the email addresses in another table, call the field with the email address mailee for example then

If($values["Material_Issue"] == True)

{
$message="";

$subject=$branch." - Root Cause Entry for Material Issue";

foreach($values as $field=>$value)

$branch=$values["Branches"];

$mailee=$values["mailee"];

$message.= $field." : ".$value."\r\n";

mail($mailee, $subject, $message);
}



This will allow for different values within the for each loop too. Just give it a try and see what happens!!!!!

If you want multiple conditions in the If clause, try

If(($values["Material_Issue"] == True) AND ($values["Branches"] == "Ohio"))


All of the condition must be in a pair of brackets, and it is better to bracket together all the individual bits inside it too, like I have.

This site has loads of helpful bits to help the move from access <shudder>