嗨我想从数据库中列出我的所有表格并按时间排序,我怎么能这样做到目前为止我可以从数据库中列出我的所有表格,但我不能按时间排序;
$dbname = "album";
if (!mysql_connect("localhost", "root", "")) {
echo "Could not connect to mysql";
exit;
}
$sql = "SHOW TABLES FROM $dbname";
$result = mysql_query($sql);
if (!$result) {
echo "DB Error, could not list tables\n";
echo "MySQL Error: " . mysql_error();
exit;
}
$sorts = array();
while ($row = mysql_fetch_row($result)) {
echo "Table: {$row[0]}"."<br>";
}
mysql_free_result($result);
答案 0 :(得分:3)
这可能会对您有所帮助:
$sql = "
SELECT create_time, table_name
FROM information_schema.tables
WHERE table_schema = '$dbname'
ORDER BY create_time
";
同时更改while循环的内部部分如下:
while ($row = mysql_fetch_array($result)) {
echo "Table: {$row['table_name']} - {$row['create_time']} <br/>";
}
答案 1 :(得分:0)
select * from information_schema.columns
order by create_time, column_name, table_name;
或者如果您想要更窄的结果集:
select column_name, table_name, data_type, character_maximum_length,
is_nullable, column_default, create_time
from information_schema.columns
order by create_time, column_name, table_name;
答案 2 :(得分:0)
这可能是解决方案
select * from information_schema.columns
order by create_time, column, table;