Forum Moderators: coopster

Message Too Old, No Replies

Writing an email with line break only after fields with data

         

tcady

8:33 pm on Oct 29, 2004 (gmt 0)

10+ Year Member



dmorison, thanks for helping me with that other question,it appears to be working great -
next question,
I want the email i get to only have a line break if there is data in a field I write to the email.

For example my form has many rows each with a quantity field...in the email I get, I want the results to be written each on a new line but only if the field had a value:

Item 1 Quantity=34
Item 4 Quantity=7
Item 9 Quanity=2

I am writing my email like this in the PHP file:
$message=
"$item1 $quantity1
$item2 $quantity2
$item3 $quantity3
$item4 $quantity4
$item5 $quantity5
etc" .

If I use a <BR> after each line it puts a break wehter there is data for $item/$quantty or not....thought the line is blank - how can I say if $item5!= nothing then add a <BR>
or is there anohther way?

jatar_k

8:37 pm on Oct 29, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



are those the actual varnames?
how many are there total?

if so I have a thought ;)

tcady

10:05 pm on Oct 29, 2004 (gmt 0)

10+ Year Member



yes they are the actual var names, there are 47 of each.
I'll be back to read your idea and implemnt it on Monday! thanks ahead of time.
tiff

jatar_k

10:40 pm on Oct 29, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



perfect

$message = "";
$counter = 1;
while ($counter <= 47) {
if (!empty(${'quantity' . $counter})) $message .= ${'item' . $counter} . ' = ' . ${'quantity' . $counter} . '<br>';
$counter++;
}

I initialized the message var but wasn't sure if you used it hiogher up in the code or not.

tcady

5:08 pm on Nov 1, 2004 (gmt 0)

10+ Year Member



That worked beautifully, thanks!