php - Grouping rows together with the same parent-ID -
i writing private-messaging script. however, have run few problems on mysql end. i've got partially working.
an example:
messageid | parentid | subject | flags 1 null 'foobar' 2 //has been read 2 1 'foobar' 2 //has been read 3 1 'foobar' 1 //has not been read
messageid: auto-incremented of message
parentid: messageid of first-message in thread
subject: subject (or title) of thread
flags: bit-wise flags (1 = unread; 2 = read)
the problems (which can me solve)
1. way have setup right now, script display message-thread in unread-messages page , read-messages page. goal display in unread-messages page until been read.
here query
//$_get['node'] allowed be: unread, read, or sent $wftype = $_get['node'] == 'sent' ? 'sender' : 'recipient'; $filter = $_get['node'] == 'sent' ? '' : ' , (`flags` & '.$message_flags[$_get['node']].') != 0'; //$filter = ($_get['node'] == 'unread' || $_get['node'] == 'read') ? ($_get['node'] == 'read' ? ' , (`flags` & '.$message_flags['read'].') != 0' : ' , (`flags` & '.$message_flags['unread'].') != 0') : ''; $result = $sql->query('select `messageid`, `parent`, `senderid`, `sender`, `subject`, max(`sendtime`) `sendtime` `memberpostbox` `'.$wftype.'id` = '.$_session['client']['number'].$filter.' , (`flags` & '.$message_flags[$wftype.'_deleted'].') = 0 group `parent` order `sendtime` desc');
will have restructure table or change how i'm doing this? or, can accomplished have now?
additional information
table-structure
create table if not exists `memberpostbox` ( `messageid` bigint(20) unsigned not null auto_increment, `parentid` int(10) unsigned default null, `senderid` varchar(255) collate utf8_unicode_ci not null, `sender` varchar(255) collate utf8_unicode_ci not null, `recipientid` varchar(255) collate utf8_unicode_ci not null, `recipient` varchar(255) collate utf8_unicode_ci not null, `subject` varchar(255) collate utf8_unicode_ci default null, `message` longtext collate utf8_unicode_ci not null, `sendtime` int(10) unsigned not null, `flags` tinyint(3) unsigned not null default '0', primary key (`messageid`), key `groupid` (`parentid`), fulltext key `search` (`subject`,`message`) engine=myisam default charset=utf8 collate=utf8_unicode_ci auto_increment=22 ;
for unread messages
'select .... memberpostbox flag=1'
for read message
'select .... memberpostbox flag=2'
only flag determining if message read or not, part involve display correct list..... of course have add rest of code in there.
// read $result = $sql->query( 'select `messageid`, `parent`, `senderid`, `sender`, `subject`, max(`sendtime`) `sendtime` `memberpostbox` `recipientid` = '.$_session['client']['number'].$filter.' , `flags` = 2 , '.$message_flags[$wftype.'_deleted'].' = 0 group `parent` order `sendtime` desc' );
Comments
Post a Comment