我想創建一個類似於facebook收件箱的聊天框。sql聊天羣組同樣聊天
select * from chat where id in(select max(id) from chat where `to`='$user' or `from`='$user' group by `from`)order by id desc"
的問題是:
約翰發送消息給瑪麗 瑪麗發送到約翰
它會顯示2分的結果。我只想在一個選擇中將john和marie之間的這個對話分組(就像facebook一樣)。我怎麼能在同一時間從他們分組?
CREATE TABLE IF NOT EXISTS `chat` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`from` varchar(255) NOT NULL DEFAULT '',
`to` varchar(255) NOT NULL DEFAULT '',
`message` text NOT NULL,
`sent` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`recd` int(11) UNSIGNED NOT NULL DEFAULT '0',
);
還有一個'對話'表,並且使用對話ID標記每個消息。 –