On my topics list I can display the latest topics by there date_created.
But lets say if there has been a topic created example two days ago with no reply and then some one reply's to it. How to make sure that topic shows at the list.
I have attached a image of the database table
databse.png (Size: 26 KB / Downloads: 12)
Topic_model.php (Size: 1.58 KB / Downloads: 2)
But lets say if there has been a topic created example two days ago with no reply and then some one reply's to it. How to make sure that topic shows at the list.
I have attached a image of the database table
PHP Code:
<?php
class Topic_model extends CI_Model
{
public function __construct()
{
parent::__construct();
}
public function get_active_topics($fid)
{
$data = array();
$this->db->where('forum_id', $fid);
$this->db->order_by('date_created', 'desc');
$query1 = $this->db->get('topics');
foreach ($query1->result_array() as $forum_result)
{
$this->db->where('topic_id', $forum_result['topic_id']);
$this->db->where('reply_id', '0');
$this->db->order_by('date_created', 'desc');
$query2 = $this->db->get('topics');
foreach ($query2->result_array() as $topic_result)
{
$reply = $this->get_reply($topic_result['topic_id']);
$date1 = date('D M d', $topic_result['date_created']) . ' , ' . date('Y H:i:s a', $topic_result['date_created']);
$date2 = date('D M d', $reply['date_created']) . ' , ' . date('Y H:i:s a', $reply['date_created']);
$data[] = array(
'title' => $topic_result['title'],
'latest_post' => isset($reply['username']) ? $reply['username'] : $topic_result['user_id'],
'latest_post_time' => !isset($reply) ? $date2 : $date1,
);
}
}
return $data;
}
public function get_reply($reply_id)
{
$this->db->select('t.*, u.username');
$this->db->from('topics t');
$this->db->join('user u', 'u.user_id = t.user_id');
$this->db->where('t.reply_id', $reply_id);
$this->db->order_by('date_created', 'desc');
$this->db->limit(1);
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->row_array();
}
return false;
}
}

