简体   繁体   中英

PHP MySql Result as Table in html

Im trying to list the result from MySQl results as a Table in my HTML. My PHP file:

 $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();

And in HTML: block('content'); ?>

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

But I dont get any reults in the html file. What is the correct way to list all results from SQL to a Table?

I don't know if it is the right way or not but it works as this:

I create some html table

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

In here my PHP begins

 <?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 Ends I connected the table in MySQL, and selected my rows then print it with echo in html format.

                </tbody>
              </table>

Table ends

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM