public function get_comments()
{
$input = $this->getinput->json(); //先接收
if (isset($input['page'])) {
$offset = ($input['page'] - 1) * 10;
$limit = 10;
} else {
$offset = 0;
$limit = 100;
}
$query = $this->db->join('user', 'user.id = comment.user_id')->where('comment.video_id', $input['video_id'])->select(['user.nick_name','user.head_portrait','comment.*'])->offset($offset)->limit($limit)->order_by('comment.created_at', 'desc')->get('comment')->result_array();
$count = $this->db->where('video_id', $input['video_id'])->from('comment')->count_all_results();
$data = array(
'data' => $query,
'total' => $count,
);
echo json_encode($data);
}
核心代码