<?php
//query that fetch unread articles
$query = "
SELECT
articles.*
FROM
articles
LEFT JOIN
read_articles
ON articles.id != read_articles.article_id
WHERE
read_articles.user_id = 1
";
/**
Test db data
CREATE TABLE IF NOT EXISTS `articles` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO `articles` (`id`, `title`) VALUES
(1, 'Article 1'),
(2, 'Article 2');
-- --------------------------------------------------------
CREATE TABLE IF NOT EXISTS `read_articles` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`article_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO `read_articles` (`id`, `article_id`, `user_id`) VALUES
(1, 1, 1);
我已經完成了它使用參數左JOIN。這也會返回空值。因此,我可以檢查一個空值並顯示NEW標籤。 – viperfx 2011-12-18 18:26:10