Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Username Post
- demo 2
- admin 1
- Username Post
- demo 3 <-- Because the user has asked the Question / "thread" and has replied twice
- admin 1
- public function number_of_replies($user_id, $thread_id) {
- $this->db->select('*');
- $this->db->from('reply');
- $this->db->join('thread', 'thread.user_id = reply.user_id', 'left');
- $this->db->where('reply.user_id', $user_id);
- $query = $this->db->get();
- if ($query->num_rows() > 0) {
- return $query->num_rows();
- } else {
- return 0;
- }
- }
- <?php
- class Who_replied extends MX_Controller {
- public function __construct() {
- parent::__construct();
- }
- public function index($thread_id = '') {
- $data['users'] = array();
- $data['thread_id'] = $thread_id;
- $results = $this->get_users_who_replied($thread_id);
- if (isset($results)) {
- foreach ($results as $result) {
- $data['users'][] = array(
- 'user_id' => $result['user_id'],
- 'username' => $result['username'],
- 'total' => $this->number_of_replies($result['user_id'], $thread_id),
- );
- }
- }
- $data['total_posts'] = '';
- return $this->load->view('default/template/forum/categories/who_replied_view', $data);
- }
- public function get_users_who_replied($thread_id) {
- $this->db->select('user.username, user.user_id, reply.thread_id');
- $this->db->distinct();
- $this->db->from('reply');
- $this->db->join('user', 'user.user_id = reply.user_id', 'left');
- $this->db->join('thread', 'thread.user_id = user.user_id', 'left');
- $this->db->where('reply.thread_id', $thread_id);
- $this->db->order_by('thread.user_id', 'desc');
- $query = $this->db->get();
- if ($query->num_rows() > 0) {
- return $query->result_array();
- }
- }
- public function number_of_replies($user_id, $thread_id) {
- $this->db->select('*');
- $this->db->from('reply');
- $this->db->join('thread', 'thread.user_id = reply.user_id', 'left');
- $this->db->where('reply.user_id', $user_id);
- $query = $this->db->get();
- if ($query->num_rows() > 0) {
- return $query->num_rows();
- } else {
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement