2

Im stuck on an issue I just cant solve. Ive thought about how, looked it up, and have not yielded any results.

Im trying to use an array in an email, and I need a double line break between them.

Im creating two arrays from within a mysql query results loop like so:

while($row = $result->fetch_assoc()){
        $updated_email_array['Clinic']=$row['clinic_name'];
        $updated_email_array['Email_Credits_To_Add']=$row['email_allotment'];
        $updated_email_array['SMS_Credits_To_Add']=$row['sms_allotment'];
        $updated_email_array['Email_Credits_Rolling_Over']=$row['$email_left'];
        $display_email_array[] = $updated_email_array;
}

Im then parsing out the values and adding them to a variable to be nested in an email, like so:

$intouch_credit_refill_message = "Credit Refill Report\n\n";
foreach ($display_email_array as $each_member) { 
    while (list($key, $value) = each ($each_member)) { 

        $intouch_credit_refill_message .= "$key: $value\n"; 

    } 

}

Lastly, im sending $intouch_credit_refill_message in an email

mail($email address,"Credit Refill Record",$intouch_credit_refill_message,"From: [email protected]");

This gives me:

Credit Refill Report

Clinic: Royal York Animal Hospital
Email_Credits_To_Add: 5000
SMS_Credits_To_Add: 500
Email_Credits_Rolling_Over: 100200
Smail_Credits_Rolling_Over: 10050
New_Email_Credit_Allotment: 105200
New_SMS_Credit_Allotment: 10550
Clinic: Jason's Test Clinic
Email_Credits_To_Add: 5000
SMS_Credits_To_Add: 500
Email_Credits_Rolling_Over: 75000
Smail_Credits_Rolling_Over: 7500
New_Email_Credit_Allotment: 80000
New_SMS_Credit_Allotment: 8000

But I Need:

Credit Refill Report

Clinic: Royal York Animal Hospital
Email_Credits_To_Add: 5000
SMS_Credits_To_Add: 500
Email_Credits_Rolling_Over: 100200
Smail_Credits_Rolling_Over: 10050
New_Email_Credit_Allotment: 105200
New_SMS_Credit_Allotment: 10550

Clinic: Jason's Test Clinic
Email_Credits_To_Add: 5000
SMS_Credits_To_Add: 500
Email_Credits_Rolling_Over: 75000
Smail_Credits_Rolling_Over: 7500
New_Email_Credit_Allotment: 80000
New_SMS_Credit_Allotment: 8000

I cant figure out how to add a break like that between the arrays in the loop where they are added to the email line.

Thank you for any help you might give.

1
  • why don't you just put break before Clinic and single break after heading ? Commented Jan 26, 2015 at 18:00

2 Answers 2

1

Just add another new line in your foreach loop like this:

foreach ($display_email_array as $each_member) { 
    while (list($key, $value) = each ($each_member)) { 

        $intouch_credit_refill_message .= "$key: $value\n"; 

    } 

    $intouch_credit_refill_message .= "\n";

}
Sign up to request clarification or add additional context in comments.

1 Comment

I kept trying to force it inside the while loop... Its very obvious after you gave your answer that this is what I should have done.
0

At any-time in PHP if you need a line break or a tab just do this

echo "\r\n";

echo "\t";

You can also use PHP_EOL when you want a new line, and you want to be cross-platform.

php reference:

PHP_EOL (string) The correct 'End Of Line' symbol for this platform. Available since PHP 5.0.2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.