jason310771 Posted December 7, 2012 Share Posted December 7, 2012 How do I get the following results.. The userid and the total number of unread messages they have. CREATE TABLE IF NOT EXISTS `privateMessages` ( `id` int(11) NOT NULL AUTO_INCREMENT, `convo_id` int(11) NOT NULL DEFAULT '0', `sent_by` text NOT NULL, `sent_to` text NOT NULL, `subject` varchar(255) NOT NULL, `message` text NOT NULL, `sent_to_deleted` tinyint(1) NOT NULL DEFAULT '0', `sent_by_deleted` tinyint(1) NOT NULL DEFAULT '0', `status` tinyint(1) NOT NULL DEFAULT '0', `timestamp` datetime NOT NULL, `read` int(11) NOT NULL DEFAULT '0', `emailNotified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `reportedby` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=85 ; -- -- Dumping data for table `privateMessages` -- INSERT INTO `privateMessages` (`id`, `convo_id`, `sent_by`, `sent_to`, `subject`, `message`, `sent_to_deleted`, `sent_by_deleted`, `status`, `timestamp`, `read`, `emailNotified`, `reportedby`) VALUES (84, 83, 'ABC4EF', '1', '111', '22222', 0, 0, 0, '2012-12-07 16:18:50', 0, '0000-00-00 00:00:00', ''), (83, 83, '1', 'ABC4EF', '111', '111', 0, 0, 0, '2012-12-07 16:09:23', 0, '0000-00-00 00:00:00', ''); Quote Link to comment https://forums.phpfreaks.com/topic/271724-return-count-of-unread-messages-for-each-user/ Share on other sites More sharing options...
Barand Posted December 7, 2012 Share Posted December 7, 2012 SELECT sent_to, COUNT(*) as total FROM privateMessages WHERE read = 0 GROUP BY sent_to Quote Link to comment https://forums.phpfreaks.com/topic/271724-return-count-of-unread-messages-for-each-user/#findComment-1398133 Share on other sites More sharing options...
jason310771 Posted December 7, 2012 Author Share Posted December 7, 2012 Great thank you, Quote Link to comment https://forums.phpfreaks.com/topic/271724-return-count-of-unread-messages-for-each-user/#findComment-1398143 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.