i developing custom forum php , mysql. have 3 primary tables in scenario: boards, threads, , messages. count number of messages in board. threads table has column called "first_msg_id" reference first message of thread. query shouldn't count message.
create table if not exists `forum_messages` ( `message_id` int(15) not null auto_increment, `thread_id` int(15) not null, `author_id` int(15) not null, `modifier_id` int(15) default null, `content` text not null, `date_posted` timestamp not null default current_timestamp on update current_timestamp, `date_modified` timestamp null default null, primary key (`message_id`) ) engine=innodb default charset=latin1; create table if not exists `forum_threads` ( `thread_id` int(15) not null auto_increment, `board_id` int(15) not null, `first_msg_id` int(15) not null, `last_msg_id` int(15) not null, `author_id` int(15) not null, `updater_id` int(15) not null, `title` text not null, `date_posted` timestamp not null default current_timestamp on update current_timestamp, `date_updated` timestamp not null default '0000-00-00 00:00:00', `views` int(15) not null, `status` tinyint(1) not null, `type` tinyint(1) not null comment '0 normal, 1 sticky, 2 global.', primary key (`thread_id`) ) engine=innodb default charset=latin1; create table if not exists `forum_boards` ( `board_id` int(15) not null auto_increment, `parent_id` int(15) not null, `category_id` int(15) not null, `last_msg_id` int(15) not null, `position` tinyint(1) not null, `title` text not null, `description` text not null, `status` tinyint(1) not null, `thread_count` int(15) not null, `reply_count` int(15) not null, primary key (`board_id`) ) engine=innodb default charset=latin1;
this query have:
$query_board_replies = " select m.message_id, m.thread_id, t.thread_id, t.first_msg_id, t.board_id forum_messages m left join forum_threads t on t.first_msg_id != m.message_id t.board_id = ".$board_id." order m.message_id";
it doesn't return errors, giving me incorrect count. there 2 actual replies, returning count of 18 in particular board.
any ideas?
this should it.
$query = " select count(*) forum_messages a, forum_threads b a.thread_id = b.thread_id , a.message_id != b.first_msg_id , b.board_id = " . mysqli_real_escape_string($dbc, $board_id) . " "; $rs = mysqli_query($dbc, $query); list($count) = mysqli_fetch_array($rs); echo $count;
Comments
Post a Comment