我有以下问题。我喜欢在邮件正文中有一些行,最多10行。我从数据库中获得的行。我怎么能这样做?我的代码在这里。通过回声,我得到了"线"但我怎么能把它放在变量中,我喜欢在我的邮件消息体中使用?
mysql_query("SET NAMES 'utf8'");
$sql = "SELECT * FROM multi_booking WHERE booking_no = '{$_GET['booking']}'";
$ergebnis_sub = mysql_query($sql);
while ($row_sub = mysql_fetch_object($ergebnis_sub))
{
mysql_query("SET NAMES 'utf8'");
$sql1 = "SELECT * FROM multi_orders WHERE booking_no = '{$_GET['booking']}'";
$result = mysql_query($sql1);
$row_count = mysql_num_rows($result);
for($i = 1; $i <= $row_count; $i++)
{
$row = mysql_fetch_array($result);
echo("Service[$i]. {$row['Services']}\n");
}
$idbooking = $row_sub->idbooking;
$name = $row_sub->name;
$email = $row_sub->email;
$blang = $row_sub->lang;
$country = $row_sub->country;
$arrivaldate = $row_sub->arrivaldate;
$accommodation = $row_sub->accommodation;
$totalamount = $row_sub->totalamount;
$invoice = $row_sub->invoice;
$comment = $row_sub->comment;
$message2 = "
Subject: Booking $invoice<br />
-----------------------------------------------------------------------------------------------------------<br />
Name: $name<br />
EMail: $email<br />
Language: $blang<br />
Country: $country<br />
Arrival Date: $arrivaldate<br />
Hotel: $accommodation<br />
Service 1: '$service[1]'<br />
Service 2: $service[2]<br />
Service 3: $service[3]<br />
Service 4: $service4<br />
Service 5: $service5<br />
Service 6: $service6<br />
Service 7: $service7<br />
Service 8: $service8<br />
Service 9: $service9<br />
Service 10: $service10<br />
Total amount: $totalamount<br />
Booking Invoice: $invoice<br />
Booking Comment: $comment<br />
-----------------------------------------------------------------------------------------------------------<br />
Please check in the admin section for the follow booking number: $invoice
";
}
答案 0 :(得分:0)
您可以使用.
运算符连接字符串,这样就可以将它们组合成一个变量。
$lines = "";
for($i = 1; $i <= $row_count; $i++)
{
$row = mysql_fetch_array($result);
$lines = $lines . "Service[$i]. {$row['Services']}\n");
}
然后,您可以将这些行与消息组合在一起,就像使用其他变量一样。
$message2 = "
Subject: Booking $invoice<br />
-----------------------------------------------------------------------------------------------------------<br />
Name: $name<br />
EMail: $email<br />
Language: $blang<br />
Country: $country<br />
Arrival Date: $arrivaldate<br />
$lines
Total amount: $totalamount<br />
Booking Invoice: $invoice<br />
Booking Comment: $comment<br />";
您也可以使用简写.=
,就像使用+=
向变量添加内容一样。下面两行是相同的:
$mystring = $mystring . 'x';
$mystring .= 'x';