herdoc字符串php问题

herdoc字符串php问题,php,mysql,sql,heredoc,Php,Mysql,Sql,Heredoc,我正在尝试用heredoc撰写电子邮件内容。我不知道如何访问以前一些sql查询中存储的变量,并将它们插入到文本中 以下是sql查询: $week=mysql_query('SELECT `Name`, `fname`, `Marca` FROM `personal` WHERE (`Responsabil`='.$id.') AND (`Protectie`>="'.$CurrentDate.'") AND (`Protectie`<"'.$WeekDate.'") AND (`No

我正在尝试用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;

我需要在这里插入所有查询结果的名称。查询已经过测试并正常工作。

您需要将结果变量用花括号括起来,以使它们正确显示在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);
试试这个

$content=<<<EMAIL
We inform you that the following people:
{$week['name']} {$week['fname']}
{$exp['name']} {$exp['fname']}
are due for inspection.
EMAIL;

请注意,这将只打印一条记录,如果要显示结果集中的所有记录,则需要在resultset上循环。

出现了什么错误?分析错误:语法错误、意外的T_封装的_和_空格、预期的标识符T_字符串或变量T_变量或数字T_NUM_字符串。它不喜欢带$week的like中的“”。。您的电子邮件后面有空格;这是可行的,但是我如何发布$week中的洞内容呢。如果$week是一个名称数组,您可以从数组结果中构建一个字符串:$str=;对于每个$week['Name']作为$Name{$str.=$Name;}然后在循环之后,将$str放入Heredoc@iswinky您还可以在数组中使用$week[fname]引号redundant@insanebits我不知道!是从5.4开始的吗?这会有用的。我现在唯一的问题是文本中没有显示换行符
$content=<<<EMAIL
We inform you that the following people:
{$week['name']} {$week['fname']}
{$exp['name']} {$exp['fname']}
are due for inspection.
EMAIL;