How to use 'distinct' in zend db model

Viewed 23863

I have search for a long time to get this thing work.

What I want is to know how I user the 'distinct' in a zend db model to make my selection for the followers of a user unique.

My db model to count followers for a user (here I need to add the 'distinct')

public function countFollowers($user_id) 
{    
    $rowset       = $this->fetchAll("user_id = $user_id");
    $rowCount     = count($rowset);

    if ($rowCount > 0) {
      return $rowCount;
    } else {
      return $rowCount;
    }
}

EDIT: This function is part of 'class Application_Model_DbTable_Followers extends Zend_Db_Table_Abstract'

My table structure

  • id
  • article_id // Id of the article who is written by 'user_id'.
  • user_id // user_id owner of the article
  • follower_id // member who has following this article
  • date // date of follow

'user_id' can be written various articles, the follower can follow various articles of the same writer. I want to make a unique follower count. As an example what I want, If a follower is following 8 articles of one writer it has to be compared to '1' in the count.

I hope this will be clear enough to understand what I tried to reach.

With kind regards,

Nicky

6 Answers
Related