Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP在HTML表中显示对象数组并将其作为电子邮件发送_Php_Html_Arrays_Html Table - Fatal编程技术网

使用PHP在HTML表中显示对象数组并将其作为电子邮件发送

使用PHP在HTML表中显示对象数组并将其作为电子邮件发送,php,html,arrays,html-table,Php,Html,Arrays,Html Table,我想向我的用户发送电子邮件,并且数据在一个对象数组中,所以我想在HTML表中显示数据并将其作为电子邮件发送。我不知道我做错了什么 这是数据的样本 [ {"created":"2020-02-05","cat":"Transport","amount":7000,"comment":"The accommodation "}, {"created":"2020-02-05","cat":"Accomodation","amount":9000,"comment":"goimg ibadan

我想向我的用户发送电子邮件,并且数据在一个对象数组中,所以我想在HTML表中显示数据并将其作为电子邮件发送。我不知道我做错了什么

这是数据的样本

[
  {"created":"2020-02-05","cat":"Transport","amount":7000,"comment":"The accommodation "},
  {"created":"2020-02-05","cat":"Accomodation","amount":9000,"comment":"goimg ibadan"}
]
这就是我迄今为止所尝试的:

$html = "<html>
   <body> <h1> Mr. $data->names  Claim expense on  $data->created </h1>
    With below information <br>";
$html .="
      <table>
        <tr>
          <td> Date </td><td> Category </td><td> Amount </td> <td> Description </td>
        </tr> $claim";

foreach($claim  as $row ){
  $html .="<tr>
      <td>{$row->created }</td><td>{$row->cat}</td><td>{$row[amount]}</td><td>{$row[comment]}</td>
     </tr>";
}

$html .=  "<tr>
      <td> Advance : $data->advance </td><td> Total Amount : $data->total </td><td> GrandTotal : $data->granTotal </td> <td>  </td>
    </tr>
  </table>";
$html .="<p>you can login to approve or disapprove this request</p>
  </body></html>";
$html=”
$data先生->姓名索赔$data费用->已创建
包含以下信息
”; $html.=” 日期类别金额说明 美元索赔”; foreach($行索赔){ $html.=” {$row->created}{$row->cat}{$row[amount]}{$row[comment]} "; } $html.=” 预付款:$data->预付款总额:$data->总额:$data->总额 "; $html.=“您可以登录以批准或不批准此请求

";
在上网和研究之后,我后来意识到,我必须做一些共同的事情,下面的代码解决了这个问题

```$tbclaim= "<table class='table table-bordered table-responsive table-info' style='border: #4f1915 thick'>
                  <tr>
                  <td> Date </td><td> Category </td><td> Amount </td> <td> Description </td>
                  </tr>";
                  for($i = 0; $i < sizeof($data["claim"]); $i++){
                    $tbclaim .= "<tr style='background-color: green; color: #ffffff;'  >";
                    $tbclaim .= "<td>" . $data["claim"][$i]["created"] . "</td>";
                    $tbclaim .= "<td>" . $data["claim"][$i]["cat"] . "</td>";
                    $tbclaim .= "<td>" . $data["claim"][$i]["amount"] . "</td>";
                    $tbclaim .= "<td>" . $data["claim"][$i]["comment"] . "</td>";
                    $tbclaim .= "</tr>";
                  }
                   $tbclaim .= "</table>";```**strong text**
``$tbclaim='
日期类别金额说明
";
对于($i=0;$i
不清楚问题出在哪里。运行此代码时实际会发生什么?您是否收到错误或某些意外输出?请提供更多详细信息。此外,您的数据看起来像一个JSON字符串。所以你不能像那样直接在PHP中使用它。在尝试使用它之前,您是否先使用json_decode()将其转换为对象?同样不清楚-示例数据和代码中的
$data
对象之间没有明显的联系。我还可以看到一些潜在的语法错误,例如
$row[amount]
$row[comment]
应该是
$row[“amount”]
$row[“comment”]
,甚至是
$row->amount
$row->comment
(取决于$data变量的结构)。因此,请具体告诉我们您面临的问题,然后我们可以缩小问题范围并给您提供更好的建议。以下是前端{“索赔”:[{“创建”:“2020”,“cat”:“Accomod”,“amount”:1000的原始JSON数据,“评论”:“th”},{“创建”:“02-08”,“cat”:“Trans”,“amount”:10,“comment”:“Transport”。},{“创建”:“12345”,“cat”:“Others”,“amount”:3000,“comment”:“Daily”}],“total”:8000,“grandtotal”:7000,“advance”:“1000”,“userId”:“18”}