0

我从未尝试过,但想从几个不同的表中回显数据并按时间戳对它们进行排序。我提出的代码带有一个布尔值,我不知道为什么。

 <?php
$result = mysql_query("SELECT * FROM artists ORDER BY timestamp DESC
UNION
SELECT * FROM news ORDER BY timestamp DESC
UNION
SELECT * FROM tracks ORDER BY timestamp DESC
UNION
SELECT * FROM gigs ORDER BY timestamp DESC
UNION
SELECT * FROM feature ORDER BY timestamp DESC");

while($row = mysql_fetch_array($result)){echo'News: <a      href="index.html">'.$row['name'].$row['title'].$row['trackname'].$row['gigname'].'</a><br>'     ;}

?>
4

1 回答 1

0

假设您的表属于 UNION 函数的约束。

尝试:

SELECT * FROM 
    (SELECT * FROM artists ORDER BY timestamp DESC
    UNION
    SELECT * FROM news ORDER BY timestamp DESC
    UNION
    SELECT * FROM tracks ORDER BY timestamp DESC
    UNION
    SELECT * FROM gigs ORDER BY timestamp DESC
    UNION
    SELECT * FROM feature ORDER BY timestamp DESC) as temp
ORDER by timestamp DESC;
于 2012-06-10T03:42:48.037 回答