List all MySQL tables and exclude them


I am trying to return all MySQL tables from a database and exclude them, for example, with users. I use the following code to print table names:

function findTables() { global $conn; global $DB; $query = "SHOW TABLES FROM $DB "; $showTablesFromDb = mysqli_query($conn, $query); while($row = mysqli_fetch_row($showTablesFromDb)) { echo "<li><a href='admin.php?show={$row[0]}'>{$row[0]}</a></li>"; } } 
+6
source share
2 answers

The solution will be:

 show tables where tables_in_$DB not like 'a%'; 

Here are some demos:

 mysql> show tables; +-----------------+ | Tables_in_test3 | +-----------------+ | a1 | | t1 | | t2 | +-----------------+ 3 rows in set (0.00 sec) -- LIKE is simpler than NOT LIKE mysql> show tables like 'a%'; +----------------------+ | Tables_in_test3 (a%) | +----------------------+ | a1 | +----------------------+ 1 row in set (0.00 sec) -- `show tables not like 'a%'` is not working, -- use the following way for NOT LIKE matching mysql> show tables where tables_in_test3 not like 'a%'; +-----------------+ | Tables_in_test3 | +-----------------+ | t1 | | t2 | +-----------------+ 2 rows in set (0.01 sec) 
+6
source

If the answer above does not work, try the following:

 SHOW TABLES FROM $DB WHERE Tables_in_$DB NOT LIKE 'foo' 
+2
source

All Articles