这是我的email.php页面编码。我的php电子邮件功能代码完美运行。我在这里面临一个小问题。我没有在while($t_row = mysql_fetch_array($tariff_query)){}
内获取数据库记录。但是,它正确地从数据库发送剩余的记录。如何发送while($t_row = mysql_fetch_array($tariff_query)){}
内的数据库记录?
include("config.php");
if(isset($_GET["id"]))
{
$id = mysql_real_escape_string($_GET["id"]);
$query = mysql_query("SELECT * FROM ebvouchers WHERE VoucherID = $id");
$row = mysql_fetch_object($query);
echo mysql_error();
$tariff_query = mysql_query("SELECT * FROM ebvouchertariffs WHERE VoucherID_Fk = $id");
$strMessage = "<table width=1200 align=center cellpadding=0 cellspacing=0 bgcolor=#FFFFFF>
<tr>
<td width=1026 height=8 colspan=2> </td>
</tr>
<tr>
<td colspan=8>
<table class=glow width=1070 border=0 align=center cellpadding=0 cellspacing=0>
<tr>
<td height=40 colspan=4 style=border-radius: 5px 5px 0px 0px; class=headdetail>GUEST DETAILS </td>
</tr>
<tr>
<td width=263 height=10 class=detailsfont> </td>
<td width=228> </td>
<td width=239 class=detailsfont> </td>
<td width=340> </td>
</tr>
<tr>
<td height=40 class=detailsfont>Voucher ID :</td>
<td width=228 class=fetchfont>$row->VoucherID</td>
<td width=239 class=detailsfont>Voucher Reference Number :</td>
<td width=340 class=fetchfont>$row->VoucherReference</td>
</tr>
//some codes
//some codes
//some codes
//some codes
//some codes
//some codes
//some codes
<tr>
<td colspan=4>
<table class=myborder width=1050 border=0 align=center cellpadding=10 cellspacing=0>
<tr>
<td width=70 height=40 class=tarifffont>Serial No</td>
<td width=130 class=tarifffont>Date</td>
<td width=250 class=tarifffont>Particulars</td>
<td width=100 class=tarifffont>No of Nights</td>
<td width=100 class=tarifffont>Rate</td>
<td width=100 class=tarifffont>Price</td>
<td width=100 class=tarifffont>Tax %</td>
</tr>";
while($t_row = mysql_fetch_array($tariff_query))
{
"<tr>
<td class=insidetariff>". $t_row['TariffSlNo'] ."</td>
<td class=insidetariff>". $t_row['TariffDate'] ."</td>
<td class=fetchfont>". $t_row['TariffParticulars'] ."</td>
<td class=insidetariff>". $t_row['NoOfNights'] ."</td>
<td class=insidetariff>". $t_row['TariffRate'] ."</td>
<td class=insidetariff>". $t_row['TariffPrice'] ."</td>
<td class=insidetariff>". $t_row['TariffTax'] ."</td>
</tr>";
}
"<tr>
<td height=40 colspan=2 class=detailsfont>Total Price (Overall Price) : </td>
<td height=20 colspan=2 class=tarifffont>$tt_row->TariffAddTotal</td>
<td height=20 class=insidetariff>Net Total (Overall Tax) : </td>
<td height=20 colspan=2 class=tarifffont>$tt_row->TariffNetTotal</td>
</tr>
<tr>
<td height=20 colspan=7 class=detailsfont> </td>
</tr>
<tr>
<td height=40 colspan=5 class=detailsfont>Final Amount : </td>
<td height=40 colspan=2 class=tarifffont>$tt_row->TariffFinalTotal</td>
</tr>
</table></td>
</tr>
<td colspan=4> </td>
</table>
</td>
</tr>";
}
答案 0 :(得分:1)
您必须将数据附加到字符串。所以代码将是这样的:
while ($t_row = mysql_fetch_array($tariff_query)) {
$strMessage .= "<tr>
<td class=insidetariff>". $t_row['TariffSlNo'] ."</td>
<td class=insidetariff>". $t_row['TariffDate'] ."</td>
<td class=fetchfont>". $t_row['TariffParticulars'] ."</td>
<td class=insidetariff>". $t_row['NoOfNights'] ."</td>
<td class=insidetariff>". $t_row['TariffRate'] ."</td>
<td class=insidetariff>". $t_row['TariffPrice'] ."</td>
<td class=insidetariff>". $t_row['TariffTax'] ."</td>
</tr>";
}
$strMessage .= "<tr>
<td height=40 colspan=2 class=detailsfont>Total Price (Overall Price)....
此外,不推荐使用mysql_*
函数,将来也会将其删除。您现在应该使用mysqli_*
函数。
答案 1 :(得分:1)
你错了方法。首先将循环数据分配给变量然后添加到这样的邮件消息:
$tbl = '';
while($t_row = mysql_fetch_array($tariff_query))
{
$tbl .= "<tr>
<td class=insidetariff>". $t_row['TariffSlNo'] ."</td>
<td class=insidetariff>". $t_row['TariffDate'] ."</td>
<td class=fetchfont>". $t_row['TariffParticulars'] ."</td>
<td class=insidetariff>". $t_row['NoOfNights'] ."</td>
<td class=insidetariff>". $t_row['TariffRate'] ."</td>
<td class=insidetariff>". $t_row['TariffPrice'] ."</td>
<td class=insidetariff>". $t_row['TariffTax'] ."</td>
</tr>";
}
现在你在消息上添加这个变量:
$strMessage = "<table>.....".$tbl."....";
答案 2 :(得分:0)
您没有连接变量$strMessage
的字符串。
在while
循环中,您应该将字符串与变量相连,最后echo
。
答案 3 :(得分:0)
将在while循环中计算的数据存储为:
while($t_row = mysql_fetch_array($tariff_query))
{
$strMessage .= "<tr>
<td class=insidetariff>". $t_row['TariffSlNo'] ."</td>
<td class=insidetariff>". $t_row['TariffDate'] ."</td>
<td class=fetchfont>". $t_row['TariffParticulars'] ."</td>
<td class=insidetariff>". $t_row['NoOfNights'] ."</td>
<td class=insidetariff>". $t_row['TariffRate'] ."</td>
<td class=insidetariff>". $t_row['TariffPrice'] ."</td>
<td class=insidetariff>". $t_row['TariffTax'] ."</td>
</tr>";
}
并将while循环后的字符串分配给$ strMessage:
$strMessage .= "<tr>
<td height=40 colspan=2 class=detailsfont>Total Price (Overall Price) : </td>
<td height=20 colspan=2 class=tarifffont>$tt_row->TariffAddTotal</td>
<td height=20 class=insidetariff>Net Total (Overall Tax) : </td>
<td height=20 colspan=2 class=tarifffont>$tt_row->TariffNetTotal</td>
</tr>
<tr>
<td height=20 colspan=7 class=detailsfont> </td>
</tr>
<tr>
<td height=40 colspan=5 class=detailsfont>Final Amount : </td>
<td height=40 colspan=2 class=tarifffont>$tt_row->TariffFinalTotal</td>
</tr>
</table></td>
</tr>
<td colspan=4> </td>
</table>
</td>
</tr>";