有人可以指导我如何以WhatsApp格式显示聊天数据库表中的所有消息按日期分组消息,即
[今天]
珍妮特:怎么样? 乔恩:很好,你[昨天]
约翰:请上床睡觉
珍妮特:亲爱的,好晚上[2016年5月19日]
约翰:请上床睡觉
珍妮特:亲爱的,好晚上
MySQL的:
CREATE TABLE IF NOT EXISTS `chat` (
`id` int(10) unsigned NOT NULL,
`from` varchar(255) NOT NULL DEFAULT '',
`to` varchar(255) NOT NULL DEFAULT '',
`message` text NOT NULL,
`sent_by` varchar(111) NOT NULL,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`recd` int(10) unsigned NOT NULL DEFAULT '0'
) ENGINE=MyISAM AUTO_INCREMENT=229 DEFAULT CHARSET=latin1;
PHP:
$result = mysql_query("SELECT *FROM (SELECT * FROM `chat` WHERE `from` = '$my_id' AND `to` = '$chat_with' OR `from` = '$chat_with' AND `to` = '$my_id' ORDER BY `created` DESC LIMIT $start, $limit )tmp
ORDER BY tmp.created ASC") or die(mysql_error());
while($row = mysql_fetch_array($result)){
print"$row['from']";
echo parse_smileys(make_clickable(nl2br(stripslashes($row['message']))), $smiley_folder);
print"$row['created'] @ $msg_time";
}