Jump to content

placing if's with a variable?


dmccabe

Recommended Posts

Can anyone tell me how I can do this and make it work?

 

$message = "Username: $first_name \n 
			Surname: $surname \n
			Company: $company \n
			Location/Dept: $location \n
			Job Title: $job_title \n
			Start Date: $start_date \n
			Software Required: " . if ($prohire == "1") { "Prohire" } ." || " . if ($prolease == "1") { "Prolease" } ." || " . if ($proclaim == "1") { "Proclaim" } ." || " . if ($prolease == "1") { "Prolease" } ." || " . if ($sage == "1") { "Sage" } ." || " . if ($email == "1") { "email" } ." \n
			" . if ($other == "1") { "Other Software: $other_software \n" } ."
			" . if ($internet == "whitelist") { "Internet: Whitelist Only \n" } else { "Internet: Full - Reason: $internet_reason \n" } ."
			" . if (isset($mailing_lists)) { "Mailing Lists: $mailing_lists \n" } . "
			" . if (isset($other_reqs)) { "Mailing Lists: $other_reqs \n" } . "
			=============================================== \n 
			Requested By: $requested_by on $requested_date";

 

so that it is all part of the $message variable, but with differing results based on the results of the if's

 

Link to comment
https://forums.phpfreaks.com/topic/109389-placing-ifs-with-a-variable/
Share on other sites

you can use a if statement to set a variable but cant have if staments within them

 

if you do

$message = "Username: $first_name \n 
			Surname: $surname \n
			Company: $company \n
			Location/Dept: $location \n
			Job Title: $job_title \n
			Start Date: $start_date \n
			Software Required: "

if (statment here ) {
$message = $message."value if true"
}

$message = $message."=============================================== \n 
			Requested By: $requested_by on $requested_date";"

that will carry the begingin of your statment then you can add yoru true values

 

home that helps

ok I gave it a go your way, but am still doing something wrong:

 

$message = "Username: $first_name \n 
			Surname: $surname \n
			Company: $company \n
			Location/Dept: $location \n
			Job Title: $job_title \n
			Start Date: $start_date \n
			Software Required: ";
			if ($prohire == "1") { $message == $message."Prohire - "; } 
			if ($prolease == "1") { $message == $message."Prolease - "; } 
			if ($proclaim == "1") { $message == $message."Proclaim - "; }
			if ($prolease == "1") { $message == $message."Prolease - "; }
			if ($sage == "1") { $message == $message."Sage - "; }
			if ($email == "1") { $message == $message."E-mail - \n"; }
			if ($other == "1") { $message == $message."Other Software: $other_software \n"; }
			if ($internet == "whitelist") { $message == $message."Internet: Whitelist Only \n"; } elseif ($internet == "full") { $message == $message."Internet: Full - Reason: $internet_reason \n"; }
			if (isset($mailing_lists)) { $message == $message."Mailing Lists: $mailing_lists \n"; }
			if (isset($other_reqs)) { $message == $message."Mailing Lists: $other_reqs \n"; }
			$message == $message."=============================================== \n 
			Requested By: $requested_by on $requested_date";

 

All works but the $message stops as "Software Required:" even though I know $prohire = 1

 

Any thoughts?

Replace this:

<?php
			if ($prohire == "1") { $message == $message."Prohire - "; } 
			if ($prolease == "1") { $message == $message."Prolease - "; } 
			if ($proclaim == "1") { $message == $message."Proclaim - "; }
			if ($prolease == "1") { $message == $message."Prolease - "; }
			if ($sage == "1") { $message == $message."Sage - "; }
			if ($email == "1") { $message == $message."E-mail - \n"; }
			if ($other == "1") { $message == $message."Other Software: $other_software \n"; }
			if ($internet == "whitelist") { $message == $message."Internet: Whitelist Only \n"; } elseif ($internet == "full") { $message == $message."Internet: Full - Reason: $internet_reason \n"; }
			if (isset($mailing_lists)) { $message == $message."Mailing Lists: $mailing_lists \n"; }
			if (isset($other_reqs)) { $message == $message."Mailing Lists: $other_reqs \n"; }
			$message == $message."=============================================== \n 
?>

 

with

<?php
			if ($prohire == "1") { $message .= "Prohire - "; } 
			if ($prolease == "1") { $message .= "Prolease - "; } 
			if ($proclaim == "1") { $message .= "Proclaim - "; }
			if ($prolease == "1") { $message .= "Prolease - "; }
			if ($sage == "1") { $message .= "Sage - "; }
			if ($email == "1") { $message .= "E-mail - \n"; }
			if ($other == "1") { $message .= "Other Software: $other_software \n"; }
			if ($internet == "whitelist") { $message .= "Internet: Whitelist Only \n"; }
                                   elseif ($internet == "full") { $message .= "Internet: Full - Reason: $internet_reason \n"; }
			if (isset($mailing_lists)) { $message .= "Mailing Lists: $mailing_lists \n"; }
			if (isset($other_reqs)) { $message .= "Mailing Lists: $other_reqs \n"; }
			$message .= "===============================================\nRequested By: $requested_by on $requested_date";
?>

 

The ".=" is a shorthand for $x = $x . "xyz"

 

Ken

 

thanks again jesushax :)

 

One last thing.

 

i have a text area used for entering mailing list names, they will put multiple items in here on different lines.

 

when it send the email I get this:

 

How do I make it put them on seperate lines?

 

This is the code:

 

if (isset($mailing_lists)) { $message = $message."Mailing Lists: $mailing_lists \n"; }

 

Edit: Thanks ken for tip too

\r is used for apple systems, I think, try using \n instead. it will be correct when you send it out but will not look correct if you are trying to echo it our to the browser.

 

If you want to do a test as to what it will look like then you can use nl2br() to send it to the browser as it would look in the e-mail.

 

Ray

OK. So the mailing list names are in a text area?? my textarea does the same.

 

you can use this to get just \n I got it from the php site, just changed it a little

$mlist = mysql_real_escape_string($_POST['mailing_lists']);
$order   = array('\r\n', '\n', '\r');
$replace = '\n';
// Processes \r\n's first so they aren't converted twice.
$mailing_lists = str_replace($order, $replace, $mlist);

 

Ray

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.