php - How do store a list of sorted tables with an SQL SHOW TABLES statement?
Get the solution ↓↓↓I am using the following code to show all tables, but how do I store the tables into a sorted array:
$sql = "SHOW TABLES FROM ".$counter_database." ORDER BY TABLES DESC";
$result = $conn->query($sql);
$outArray = array();
while($table = $result->fetch_assoc()) {
$outArrayx[] = $table;
}
The following code spits out the data:
foreach ($outArrayx as $key => $value) {
foreach ($value as $keys => $values) {
$sql = "SELECT * FROM ".$values." WHERE user_id='0'";
$result = $conn->query($sql);
if (strpos($values, "ckia") === 0) {
while($table = $result->fetch_assoc()) {
$outArray[] = $table;
}
}
}
}
Answer
Solution:
Put the table names in a PHP array, and then sort the array. And if you don't nest it in the row, you don't need nested loops when you process it.
You can't useORDER BY
withSHOW TABLES
, but you can useLIKE
to select only tables that fit a pattern. Then you don't need theif
statement in your loop.
$sql = "SHOW TABLES FROM ".$counter_database." LIKE 'ckia%'";
$result = $conn->query($sql);
$outArray = array();
while($table = $result->fetch_row()) {
$outArrayx[] = $table[0];
}
sort ($outArrayx);
foreach ($outArrayx as $table) {
$sql = "SELECT * FROM ".$table." WHERE user_id='0'";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$outArray[] = $row;
}
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: object not found by the @paramconverter annotation.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.