Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. Username Post
  2. demo 2
  3. admin 1
  4.  
  5. Username Post
  6. demo 3 <-- Because the user has asked the Question / "thread" and has replied twice
  7. admin 1
  8.  
  9. public function number_of_replies($user_id, $thread_id) {
  10. $this->db->select('*');
  11. $this->db->from('reply');
  12. $this->db->join('thread', 'thread.user_id = reply.user_id', 'left');
  13. $this->db->where('reply.user_id', $user_id);
  14. $query = $this->db->get();
  15.  
  16. if ($query->num_rows() > 0) {
  17. return $query->num_rows();
  18. } else {
  19. return 0;
  20. }
  21. }
  22.  
  23. <?php
  24.  
  25. class Who_replied extends MX_Controller {
  26.  
  27. public function __construct() {
  28. parent::__construct();
  29. }
  30.  
  31. public function index($thread_id = '') {
  32. $data['users'] = array();
  33.  
  34. $data['thread_id'] = $thread_id;
  35.  
  36. $results = $this->get_users_who_replied($thread_id);
  37.  
  38. if (isset($results)) {
  39.  
  40. foreach ($results as $result) {
  41. $data['users'][] = array(
  42. 'user_id' => $result['user_id'],
  43. 'username' => $result['username'],
  44. 'total' => $this->number_of_replies($result['user_id'], $thread_id),
  45. );
  46. }
  47.  
  48. }
  49.  
  50. $data['total_posts'] = '';
  51.  
  52. return $this->load->view('default/template/forum/categories/who_replied_view', $data);
  53.  
  54. }
  55.  
  56. public function get_users_who_replied($thread_id) {
  57. $this->db->select('user.username, user.user_id, reply.thread_id');
  58. $this->db->distinct();
  59. $this->db->from('reply');
  60. $this->db->join('user', 'user.user_id = reply.user_id', 'left');
  61. $this->db->join('thread', 'thread.user_id = user.user_id', 'left');
  62. $this->db->where('reply.thread_id', $thread_id);
  63. $this->db->order_by('thread.user_id', 'desc');
  64. $query = $this->db->get();
  65.  
  66. if ($query->num_rows() > 0) {
  67.  
  68. return $query->result_array();
  69.  
  70. }
  71. }
  72.  
  73. public function number_of_replies($user_id, $thread_id) {
  74. $this->db->select('*');
  75. $this->db->from('reply');
  76. $this->db->join('thread', 'thread.user_id = reply.user_id', 'left');
  77. $this->db->where('reply.user_id', $user_id);
  78. $query = $this->db->get();
  79.  
  80. if ($query->num_rows() > 0) {
  81. return $query->num_rows();
  82. } else {
  83. return 0;
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement