我得到了与我的谈话的桌子,我需要列出所有的话题作为话题。所以,如果我是发送者或接收者,它应该把它列为一次谈话。因此,在两个用户之间,他们扮演的角色并不重要。
所以如果我得到了:
1, me, mom, "hello mom, I'm good. How are you?", 1, 23/09-2011
2, mom, me, "hello son, how are you?", 1, 22/09-2011
3, me, dad, "hello dad, how are you?", 1, 20/09-2011我想像这样展示一下:
between You and Mom - Hello mom... - 23/09-2011 - 2 messeges
between You and Dad - Hello dad... - 20/09-2011 - 1 message我似乎搞不懂这个问题。一些与众不同的东西。
我希望你们能帮我:)
更新
CREATE TABLE IF NOT EXISTS `fisk_beskeder` (
`id` int(11) NOT NULL auto_increment,
`fra` int(11) NOT NULL,
`til` int(11) NOT NULL,
`dato` varchar(50) NOT NULL,
`set` int(11) NOT NULL default '0',
`besked` text NOT NULL,
`svar` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;PHP
$sql = mysql_query(
"SELECT `fra`, `til`, `besked`, `dato`, `set`, `id`
FROM fisk_beskeder
WHERE til = ".$userid."
OR fra = ".$userid."
ORDER BY id DESC")
or die(mysql_error());更新
好了,现在起作用了。我唯一需要的就是从小组里得到最新的数据。
SELECT count(id), `id`, `fra`, if(a.fra = $cfg_brugerid, a.til, a.fra) AS other, `til`, `besked`, `dato`, `set`
FROM fisk_beskeder a
WHERE fra = $cfg_brugerid OR til = $cfg_brugerid
GROUP BY other
ORDER BY a.id DESC发布于 2011-09-24 00:48:53
也许这是:
SELECT COUNT(msg), msg, a.date, if(a.from ='me', a.to , a.from) as otherPerson
FROM table a
WHERE a.from = 'me' or a.to = 'me'
GROUP BY otherPerson发布于 2011-09-24 00:37:52
就像。
SELECT COUNT(a.msg), a.msg, a.date
FROM table a, table b
WHERE a.from = b.from
AND a.to != b.to
GROUP BY a.fromhttps://stackoverflow.com/questions/7536148
复制相似问题