我正在尝试用heredoc撰写电子邮件内容。我不知道如何访问从以前的一些SQL查询中存储的变量并将它们插入到文本中。
这是sql查询:
$week=mysql_query('SELECT `Name`, `fname`, `Marca` FROM `personal` WHERE (`Responsabil`='.$id.') AND (`Protectie`>="'.$CurrentDate.'") AND (`Protectie`<"'.$WeekDate.'") AND (`Notificat`!=1)');
$exp=mysql_query('SELECT `Name`, `fname`, `Marca` FROM `personal` WHERE (`Responsabil`='.$id.') AND (`Protectie`<"'.$CurrentDate.'") AND (`Notificat`!=1)');
$week=mysql_fetch_assoc($week);
$exp=mysql_fetch_assoc($exp);
和问题:
$content=<<<EMAIL
We inform you that the following people:
$week['Name'] $week['fname']
$exp['Name'] $exp['fname']
are due for inspection.
EMAIL;
我需要在这里插入从查询中得到的所有名称。查询经过测试并正常运行。
答案 0 :(得分:0)
您需要将结果变量包装在大括号中,以使它们在heredoc字符串中正确显示:
$week['Name'] = "Bloggs";
$week['fname'] = "Joe";
$exp['Name'] = "Doe";
$exp['fname'] = "Jane";
$content = <<<EMAIL
We inform you that the following people:
{$week['Name']} {$week['fname']}
{$exp['Name']} {$exp['fname']}
are due for inspection.
EMAIL;
var_dump($content);
返回:
string(87) "We inform you that the following people: Bloggs Joe Doe Jane are due for inspection."
答案 1 :(得分:0)
试试这个,
$content=<<<EMAIL
We inform you that the following people:
{$week['name']} {$week['fname']}
{$exp['name']} {$exp['fname']}
are due for inspection.
EMAIL;
请注意,这只会打印一条记录,如果要显示结果集中的所有记录,则需要循环结果集。