Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list tables in wordpress plugin development?

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;
            }
like image 615
Boopathi Rajan Avatar asked Feb 18 '26 13:02

Boopathi Rajan


1 Answers

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).

like image 177
VMai Avatar answered Feb 20 '26 02:02

VMai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!