【问题标题】:PHP MySql Result as Table in htmlPHP MySql 结果作为 html 中的表
【发布时间】:2020-11-22 17:51:01
【问题描述】:

我试图在我的 HTML 中将 MySQl 结果中的结果作为表格列出。 我的 PHP 文件:

 $stmt = $this->get('database_connection')
            ->executeQuery(
                'SELECT * FROM members'
            );

        while (false !== ($objMember = $stmt->fetch(\PDO::FETCH_OBJ)))
    
        $template->listTable= implode(', ',  $objMember['firstname']);

        return $template->getResponse();

在 HTML 中: 块(“内容”); ?>

    <p><?= $this->listTable ?></p>
<?php $this->endblock(); ?>

但我在 html 文件中没有得到任何结果。将 SQL 中的所有结果列出到表中的正确方法是什么?

【问题讨论】:

    标签: php mysql html-table


    【解决方案1】:

    我不知道这是否正确,但它是这样工作的:

    我创建了一些 html 表格

                 <table class="table">
                    <thead class=" text-primary">
                      <th>table header</th>
                      <th>table header 2</th>
                    </thead>
                    <tbody>
    

    我的 PHP 在这里开始

     <?php
            $query = mysqli_query($mysql_connection, "SELECT * FROM tbale WHERE conditions");
    
            while ($array = mysqli_fetch_array($query)) {
    
                          $k_exmaple_1 = $array['column1'];
    
                          $k_exmaple_2 = $array['column2'];
    
                          
                          echo "
    
                              <tr>
                                <td>$k_exmaple_1</td>
                                <td>$k_exmaple_2</td>
                              </tr>
    
                          ";
    
                        }
    
                       ?>
    

    PHP 结束 我在 MySQL 中连接了表,并选择了我的行,然后用 html 格式的 echo 打印它。

                    </tbody>
                  </table>
    

    餐桌结束

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-18
      • 1970-01-01
      • 1970-01-01
      • 2013-09-03
      • 2015-03-13
      • 1970-01-01
      • 2016-03-27
      • 2020-02-22
      相关资源
      最近更新 更多