php字符串问题


Heredoc string php problems

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

的回报:

string(87) "We inform you that the following people: Bloggs Joe Doe Jane are due for inspection."

试试这个,

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

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