我需要从几个不同的 SQL 表中回显和排序数据。我不能使用 UNION,因为所有表都非常不同(有 6 个)。我已经按时间戳对每个单独的表进行了排序,但需要按时间戳对它们进行排序,因此所有表中的最新事件位于回显的顶部。
是否有简单的 php 解决方案或 AJAX 或 jquery 解决方案?
这是我当前的代码:
<?php
$result = mysql_query("
SELECT * FROM news
UNION ALL
SELECT * FROM feature ORDER BY timestamp DESC LIMIT 2
")or die(mysql_error());
while($row = mysql_fetch_array($result)){echo'News: <a href="index.html">'.$row['title'].'</a><br>' ;}
?>
<?php
$result = mysql_query("
SELECT * FROM members WHERE artist='Y'
ORDER BY timestamp DESC LIMIT 2
")or die(mysql_error());
while($row = mysql_fetch_array($result)){echo'New Artist: <a href="artists/artist.php? artist='.$row['artistname'].'">'.$row['artistname'].'</a><br>' ;}
?>
<?php
$result = mysql_query("
SELECT * FROM gigs
ORDER BY timestamp DESC LIMIT 2
")or die(mysql_error());
while($row = mysql_fetch_array($result)){echo'New Gig: <a href="artists/gigs.php? artist='.$row['artistname'].'">'.$row['gigname'].' + '.$row['artistname'].'</a><br>' ;}
?>