带边框的动态表

时间:2019-05-06 16:39:36

标签: php mysql mysqli

我创建了一封电子邮件警报,每天发出一次,其中包含第二天要送达的帐户列表。这项工作正常,但是由于我使用的是动态表格,因此一些用户抱怨说它很难阅读且没有边界。

请参阅示例: https://ibb.co/dGTvPsG

这就是我的做法:

while($res = mysqli_fetch_array($result)) {  


$a[] = $res['Order_Number'];
$b[] = $res['Detail_ShipDate'];
$c[] = $res['ShipTo_Name'];
$d[] = $res['Status'];

$Order_Number = implode("<br />", $a);
$Detail_ShipDate = implode("<br />", $b);
$ShipTo_Name = implode("<br />", $c);
$Status = implode("<br />", $d);


$for_php_mailer = '<table style="border: 1px solid black;
width: 100%;font-size: 12px!important;">

<tr>
<th>Delivery Date</th>
<th>Order#</th>
<th>Company Name</th>
<th>Status</th>

<td>'.$Detail_ShipDate.'</td>
<td>'.$Order_Number.'</td>
<td>'.$ShipTo_Name.'</td>
<td>'.$Status.'</td>

</tr>

</table>';

相反,我需要它看起来像这样:https://ibb.co/XsVgZWv

我尝试了以下几种不同的组合,但发生了一两种情况。我从表中仅获得1条记录或一个非法的字符串偏移量错误。

我仍在学习,非常感谢您的帮助。

while($res = mysqli_fetch_array($result)) {  
foreach ( $res as $data ) 
{
$for_php_mailer ='
    <td>'.$data['Detail_ShipDate'].'</td>
    <td>'.$data['Order_Number'].'</td>
    <td>'.$data['ShipTo_Name'].'</td>
    <td>'.$data['Status'].'</td>';
}

1 个答案:

答案 0 :(得分:0)

mysqli_fetch_array函数仅获取一个结果,因此您无需使用foreach对其进行循环。您只需要遍历每个结果。您还应该使用mysqli_fetch_assoc获取关联数组。尝试类似的事情:

while ($row = mysqli_fetch_assoc($result)) {
    $for_php_mailer .='
       <td>'.$row['Detail_ShipDate'].'</td>
       <td>'.$row['Order_Number'].'</td>
       <td>'.$row['ShipTo_Name'].'</td>
       <td>'.$row['Status'].'</td>';
}

还要确保您使用串联分配运算符.=来保持追加结果,而不是覆盖$for_php_mailer变量。

有关myqsli_fetch_array的更多信息,请参阅文档:https://www.php.net/manual/en/mysqli-result.fetch-array.php

有关myqsli_fetch_assoc的更多信息,请参阅文档:https://www.php.net/manual/en/mysqli-result.fetch-assoc.php

相关问题