How do I display all tables in a database as HTML tables?

how to display data from database in php in table
how to fetch data from database in php and display in html table
php code to retrieve data from mysql database and display in html table
display sql query output in html table
how to display data from database in html table using python
how to display data from database in html table using javascript
how to retrieve data from database in html form
display data in table format in php

I have selected values from a single MySQL table and displayed them in a HTML table many times before using PHP, like this:

$query = "SELECT * FROM main";

$result = $connection->query($query);

while ($row = mysqli_fetch_assoc($result)) {
  echo "<tr>";
  echo "<td>" . $row['row1'] . "</td>";
  echo "<td>" . $row['row2'] . "</td>";
  echo "<td>" . $row['row3'] . "</td>";
  echo "<td>" . $row['row4'] . "</td>";
}

How can I display all of the tables in a certain database in the same way? I need it to be dynamic, so that if new tables are added to that database, they will show up on the webpage as well.

This is something I have tried, that doesn't seem to work. Perhaps I can get some feedback?

$query1 = "SHOW TABLES FROM db_name";

// This is equal to the number of tables in the database.
$query2 = "SELECT COUNT(*) FROM main";

$result1 = $connection->query($query1);

$result2 = $connection->query($query2);

$row2 = mysqli_fetch_assoc($result2);

$count = $row2["COUNT(*)"];

$counter = 1;

while ($row1 = mysqli_fetch_array($result1)) {
        ${getter.$counter++} = "SELECT * FROM " . $row[0];
    }

<table>
        <?php
        for ($i = 1; $i <= $count; $i++) {
                ${request.$i} = $connection->query(${getter.$i});
                while ($row3 = mysqli_fetch_assoc(${request.$i})) {
                        echo "<tr>";
                        echo "<td>" . $row['row1'] . "</td>";
                        echo "<td>" . $row['row2'] . "</td>";
                        echo "<td>" . $row['row3'] . "</td>";
                        echo "<td>" . $row['row4'] . "</td>";
                }
        }
        ?>
</table>

Thanks.


If you want to loop through all your tables and list the data from each one in a HTML table, including showing the column names, then this should work for you:

//get all the tables in the database
$sql = "SHOW TABLES FROM db_name";
$result = $connection->query($sql);

if ($result === false) die($conn->error);

//loop through the list of tables
while ($row = $result->fetch_row()) {
    echo "<h2>Table: ".$row[0]."</h2>";

    //now, for the current table, get all the data and loop through the rows
    $sql2 = "SELECT * FROM ".$row[0];
    $result2 = $connection->query($sql2);

    if ($result2)
    {
        //get the column names
        $fields = $result2->fetch_fields();
        echo "<table><thead><tr>";

        //loop through the field names and output each one as a column heading
        foreach ($fields as $fld)
        {
          echo "<th>".$fld->name."</th>";
        }
        echo "</tr></thead><tbody>";

        //get the rows
        while ($row2 = $result2->fetch_row()) {
            echo "<tr>";

            //loop through each data value in the row and output into a HTML table cell
            foreach ($row2 as $cell) {
                echo "<td>".$cell."</td>";
            }
            echo "</tr>";
        }

        echo "</tbody></table><hr>";
    }
    else
    {
      echo "Problem retrieving data for ".$row[0].": ".$conn->error;
    }
}

How to Display MySQL Table Data Tutorial, To populate a new database table with data you will first need an HTML page which will collect that data This way we will display all the records in the table:​  HTML Tables: All there is to know about them. Judging by the fact that we created wpDataTables, it’s no secret that we like tables. So much that we wrote this lengthy article about them to help out those of you who are beginners and want to learn about HTML tables. HTML tables are used for displaying data that make sense in spreadsheet software.


Updated Answer:

Try the following code

<?php

require_once('includes/api/db-config.php');
$db = Database::getInstance();
$conn = $db->getConnection();
$dbname = 'databaseName';

$sql = "SHOW TABLES FROM {$dbname}";
$result = mysqli_query($conn,$sql);

if (!$result) {
    echo 'MySQL Error: ' . mysqli_error($conn);
    exit;
}

while ($row = mysqli_fetch_row($result)) {
    $tableSql = "SELECT * FROM {$row[0]}";
    $tableResult = mysqli_query($conn,$tableSql);
    $Response = "<tr>";
    while ($tableRow = mysqli_fetch_row($tableResult)) {
        $Response .= "<td>{$tableRow["id"]}</td>";
        $Response .= "<td>{$tableRow["title"]}</td>";
        $Response .= "<td>{$tableRow["description"]}</td>";
        $Response .= "<td>{$tableRow["action"]}</td>";
        $Response .= "<td>{$tableRow["mods"]}</td>";
        $Response .= "<td>{$tableRow["date"]}</td>";
    }
    $Response .= "</tr>";

}

?>

Now you have data from all the tables one by one now you can display the data in html table.

How to Display Data from MySQL Database into HTML Table using , Useful SQL queries for MySQL to explore database schema. The query below lists all tables in all user databases. To list tables just from also get this. Get this interactive HTML data dictionary in minutes with Dataedo. For this purpose first i will create a database with name allphptricks and then create a table in database with name sports and dump dummy data into it. Steps to Display Data From Database Into HTML Table Using PHP. Create a Database. Create a Database Table. Dumping Data into Table.


this works for me

require_once('db.php');

   $dbname = 'sport';

   $sql = "SHOW TABLES FROM $dbname"; $result =
   mysqli_query($conn,$sql);

   if (!$result) {
       echo "DB Error, could not list tables\n";
       echo 'MySQL Error: ' . mysqli_error($conn);
       exit; }

   while ($row = mysqli_fetch_row($result)) {   //print_r($row);
       echo "Table: {$row[0]}\n"; }

List tables from all databases in MySQL, Useful SQL queries for MySQL to explore database schema. To list tables all user databases use this query. See live HTML data dictionary sample. just output the data as a html table. about 114.000.000 results for a three-word search. have you tried anything so theres a real problem? SamA74 October 25, 2016, 9:27am #5 This is a crude, basic


List tables in MySQL database, They consist of rows and columns and are often used on websites for the effective displaying of tabular data. So how to make a table in HTML? Oracle Tutorials - Show All Tables in the Database. By: FYIcenter.com (Continued from previous topic) How To Get a List of All Tables in the Database? If you don't like to use a SELECT statement to get a list of all tables in the current database, you can use the Reports view to do this as shown in the following tutorial example: Click menu


HTML Tables: All there is to know about them, The SELECT statement is used to select data from a database. The data If you want to select all the fields available in the table, use the following syntax:. OK I have a database on phpmyadmin (sql) and I want to display one of my tables into a table on HTML/PHP. I have searched online and can not implement this feature, so I'm wondering if someone coul


SQL SELECT Statement, The SELECT statement is used to select data from one or more tables: SELECT or we can use the * character to select ALL columns from a table: SELECT  Showing tables using the sqlite command line shell program. To show tables in a database using the sqlite command line shell program, you follow these steps: First, open the database that you want to show the tables: > sqlite3 c:\sqlite\db\chinook.db.