私は3つのテーブルを持っています: questions
、articles
およびpictures
各テーブルの行には current_timestamp 列が含まれておりposted
、id にリンクしています。3 つすべての行の結果をタイムスタンプで並べ替え、3 つのうち最新のもののみをエコーしたい (たとえば、質問が ID から最新のものである場合は、それのみを表示する)
if(count($interests) != 0){ foreach($interests as $interests_following){
$interestid = mysql_result(mysql_query("SELECT `id` FROM `interests` WHERE `name` = '$interests_following'"),0);
$interestquestions = @mysql_result(mysql_query("SELECT `question_text`, `posted` FROM `questions` WHERE `interest` = '$interests_following'"),0);
$interestarticles = @mysql_result(mysql_query("SELECT `article_title`, `posted` FROM `articles` WHERE `interest_id` = '$interestid'"),0);
$interestpictures = @mysql_result(mysql_query("SELECT `interest_pic_title`, `posted` FROM `interest_pictures` WHERE `interest_id` = '$interestid'"),0);
echo '.$interests_following.': //<Only display 1 newest item (article/picture/question here>