Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6155567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:27:26+00:00 2026-05-23T20:27:26+00:00

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

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:27:27+00:00Added an answer on May 23, 2026 at 8:27 pm

    Using distinct:

    public function countFollowers($user_id) 
    {
        $select = $this->select()
                  ->distinct()
                  ->where('user_id = ?', $user_id);
    
        $rowset = $this->fetchAll($select);
        $rowCount = count($rowset);
    
        return $rowCount;
    }
    

    EDIT: After edit in question to get count of followers of a user. You actually need to use group NOT distinct. I have tested the following query works to fetch the data to be count()ed,

    SELECT * FROM followers WHERE user_id = 1 GROUP BY user_id,
    follower_id

    I have not tested the code, but something like this should work:

    public function countFollowers($user_id) 
    {
        $select = $this->select()
                  ->where('user_id = ?', $user_id)
                  ->group(array('user_id', 'follower_id')); 
    
        $rowset = $this->fetchAll($select);
        $rowCount = count($rowset);
    
        return $rowCount;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a long time, I have been try to do this: Private Sub Search()
i have a long string variable and i want to search in it for
been trying to search the reason for this error for a long time and
Let me know if I have to make this more concise, if you don't
I have this code about binary search tree , I want Calculated efficancy for
I have search through the web to figure this out but no luck. I
I have a search method that takes in a user-entered string, splits it at
Long time user, first time asker; very new to regular expressions. I'm a designer
I have a problem with a plone-instance. On startup i get this CRITICAL Message
I search for a long time how I can define permitted logon hours on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.