I am trying to send email use codeigniter email class via passing data into the following parenthese .
$this->email->message('Whatever message you want to email')
The following works
$this->email->message('Your name is '.$data->name.'');
but the following will give the error. "unexpected if"
$this->email->message('You have ordered:'.
if(isset($result->order)){
//show order detail
}else{
"nothing"
}.'');
What is the correct way to achieve this.
and also if I want to include a foreach loop after the if(isset
how would that work.
if
is NOT a function. It cannot be used as a "data source" for variable assignments.
$foo = if(...) { ... } // illegal syntax.
should be written as
if (...) {
$foo = true result
else {
$foo = false result
}
$this->email->message('You have ordered:'. $foo);
You are looking for the "ternary operator":
<?php
$this->email->message('You have ordered: ' . isset($result->order) ? '...' : 'nothing');
Here the '...'
obviously is only a placeholder for whatever "details" you want to show. This certainly can be a previously prepared string variable.
It could be like this:
$temp = isset($result->order) ? "" : "nothing";
$this->email->message('You have ordered:'.$temp.'');