How to list tables in wordpress plugin development?

database, mysql, php, wordpress

Solution

As I said in my comment, you should use nested foreach loops.

global $wpdb;
$mytables=$wpdb->get_results("SHOW TABLES");
foreach ($mytables as $mytable)
{
    foreach ($mytable as $t) 
    {       
        echo $t . "<br>";
    }
}

Then you don't need to know the name of your database, because `SHOW TABLES` will create the column name "Tables_in_" (without < and > of course).

Problem

I want to show all table names in my plugin development. I know how to do that in core PHP. I am trying like this: ``` $mytables=$wpdb->get_results("SHOW TABLES"); foreach ($mytables as $mytable) { echo $mytable; } ```

Original source