如何在php脚本中包含html表

如何在php脚本中包含html表,php,html,Php,Html,我是HTML新手,我正在尝试用PHP发送带有表格附件的电子邮件,我能想到的最好办法是: $table = "<html> <head> <style> table { font-family: arial, sans-serif; border-collaps

我是HTML新手,我正在尝试用PHP发送带有表格附件的电子邮件,我能想到的最好办法是:

$table = "<html>
              <head>
                    <style>
                    table {
                        font-family: arial, sans-serif;
                        border-collapse: collapse;
                        width: 100%;
                    }

                    td, th {
                        border: 1px solid #dddddd;
                        text-align: left;
                        padding: 8px;
                    }

                    tr:nth-child(even) {
                        background-color: #dddddd;
                    }
                    </style>
                    </head>
                    <body>
                    <table>
                    <tr>
                      <th>Account</th>
                      <th>Credit used</th>
                      <th>Sent messages</th>
                      <th>Balance</th>
                    </tr>
                      <?php foreach ($statistics as $row) {
                    <tr>
                      <td>". $row["username"] ."</td>
                      <td>". $row["creditUsed"] ."</td>
                      <td>". $row["sentMessages"] ."</td>
                      <td>". $row["balance"] ."</td>
                    </tr>
                     }
                     ?>
                    </body>
                    </html>
                  </table>";  
$table=”
桌子{
字体系列:arial,无衬线;
边界塌陷:塌陷;
宽度:100%;
}
td,th{
边框:1px实心#dddddd;
文本对齐:左对齐;
填充:8px;
}
tr:n个孩子(偶数){
背景色:#dddddd;
}
账户
信用证使用
发送消息
平衡
";  

在我添加循环之前,它工作得很好,它被视为字符串并给出错误提示:数组到字符串的转换我不知道如何使它工作

在代码中使用引号是错误的

尝试以如下方式创建HTML结构:-

<html>
    <head>
        <style>
            table {
                font-family: arial, sans-serif;
                border-collapse: collapse;
                width: 100%;
            }

            td, th {
                border: 1px solid #dddddd;
                text-align: left;
                padding: 8px;
            }

            tr:nth-child(even) {
                background-color: #dddddd;
            }
        </style>
    </head>
    <body>
        <table>
        <tr>
          <th>Account</th>
          <th>Credit used</th>
          <th>Sent messages</th>
          <th>Balance</th>
        </tr>

          <?php foreach ($statistics as $row) {?>
                    <tr>
                      <td><?php echo $row["username"];?></td>
                      <td><?php echo $row["creditUsed"];?></td>
                      <td><?php echo $row["sentMessages"];?></td>
                      <td><?php echo $row["balance"];?></td>
                    </tr>
         }
         ?>
    </body>
</html>
</table>

在代码中使用引号是错误的

尝试以如下方式创建HTML结构:-

<html>
    <head>
        <style>
            table {
                font-family: arial, sans-serif;
                border-collapse: collapse;
                width: 100%;
            }

            td, th {
                border: 1px solid #dddddd;
                text-align: left;
                padding: 8px;
            }

            tr:nth-child(even) {
                background-color: #dddddd;
            }
        </style>
    </head>
    <body>
        <table>
        <tr>
          <th>Account</th>
          <th>Credit used</th>
          <th>Sent messages</th>
          <th>Balance</th>
        </tr>

          <?php foreach ($statistics as $row) {?>
                    <tr>
                      <td><?php echo $row["username"];?></td>
                      <td><?php echo $row["creditUsed"];?></td>
                      <td><?php echo $row["sentMessages"];?></td>
                      <td><?php echo $row["balance"];?></td>
                    </tr>
         }
         ?>
    </body>
</html>
</table>

最好在HTML中使用以下结构:

<?php foreach ($statistics as $row): ?> 
   <tr>
     <td><?= $row["username"]; ?></td>
     <td><?= $row["creditUsed"]; ?></td>
     <td><?= $row["sentMessages"]; ?></td>
     <td><?= $row["balance"]; ?></td>
   </tr>
<?php endforeach; ?>

最好在HTML中使用以下结构:

<?php foreach ($statistics as $row): ?> 
   <tr>
     <td><?= $row["username"]; ?></td>
     <td><?= $row["creditUsed"]; ?></td>
     <td><?= $row["sentMessages"]; ?></td>
     <td><?= $row["balance"]; ?></td>
   </tr>
<?php endforeach; ?>


我编辑了你的答案一点,现在可以了,谢谢。@Randoroxford很高兴帮助你:):)我编辑了你的答案一点,现在可以了,谢谢。@Randoroxford很高兴帮助你:):)