Give this a try.
$reply = rtrim($reply,",");
Using your example
$reply='{';
while($row=$this->conx->fetch_array($result)){
$user=new user();
$fullname=$user->get('fullname','id',$row['posted_by']);
$now=getdat($row['posted_on']);
$reply.='"count'.$count.'":{"id":'.$row['post_id'].',"user":"'.$fullname['fullname'].'","msg":"'.$row['msg'].'","at":"'.$now.'"},';
}
$reply.='}';
return rtrim($reply,",");}