I try to return all MySQL tables from Database and exclude specific one for example with users. I use following code to print my 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>";
}
}
To check records which are NULL, use IS NULL. However, to exclude any of the records, use the NOT IN clause. Use both of them in the same query.
A MySQL SELECT statement is used to retrieve data from a MySQL table. To exclude certain column(s) from the SELECT statement result, you can omit the column/ field name from the query.
MySQL SHOW TABLES command example To use the SHOW TABLES command, you need to log on to the MySQL server first. On opening the MySQL Command Line Client, enter your password. Select the specific database. Run the SHOW TABLES command to see all the tables in the database that has been selected.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With