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
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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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:

Mailing Lists: hostaff@xyz.com\r\nadmin@xyz.com

 

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

Link to comment
Share on other sites

\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

Link to comment
Share on other sites

hehehe thats the thing I have specified for it to use \r anywhere.  I have used \n's all the way through it, but it appears that if someone page an enter in the text area that is converting it to \r, but why?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.