you can revise your query to return the number of comments directly and assign it to ``$countComment``.
``$countselect = $db->rows('select count(id) from comment where thread_id=?',array($this->id));``