1. <tfoot id='caVy6'></tfoot>
        • <bdo id='caVy6'></bdo><ul id='caVy6'></ul>
      1. <i id='caVy6'><tr id='caVy6'><dt id='caVy6'><q id='caVy6'><span id='caVy6'><b id='caVy6'><form id='caVy6'><ins id='caVy6'></ins><ul id='caVy6'></ul><sub id='caVy6'></sub></form><legend id='caVy6'></legend><bdo id='caVy6'><pre id='caVy6'><center id='caVy6'></center></pre></bdo></b><th id='caVy6'></th></span></q></dt></tr></i><div id='caVy6'><tfoot id='caVy6'></tfoot><dl id='caVy6'><fieldset id='caVy6'></fieldset></dl></div>
        <legend id='caVy6'><style id='caVy6'><dir id='caVy6'><q id='caVy6'></q></dir></style></legend>
      2. <small id='caVy6'></small><noframes id='caVy6'>

        如何在 zend db 模型中使用“distinct"

        How to use #39;distinct#39; in zend db model(如何在 zend db 模型中使用“distinct)

        • <bdo id='kguDm'></bdo><ul id='kguDm'></ul>
        • <i id='kguDm'><tr id='kguDm'><dt id='kguDm'><q id='kguDm'><span id='kguDm'><b id='kguDm'><form id='kguDm'><ins id='kguDm'></ins><ul id='kguDm'></ul><sub id='kguDm'></sub></form><legend id='kguDm'></legend><bdo id='kguDm'><pre id='kguDm'><center id='kguDm'></center></pre></bdo></b><th id='kguDm'></th></span></q></dt></tr></i><div id='kguDm'><tfoot id='kguDm'></tfoot><dl id='kguDm'><fieldset id='kguDm'></fieldset></dl></div>
        • <legend id='kguDm'><style id='kguDm'><dir id='kguDm'><q id='kguDm'></q></dir></style></legend>
          <tfoot id='kguDm'></tfoot>
              <tbody id='kguDm'></tbody>

            <small id='kguDm'></small><noframes id='kguDm'>

                  本文介绍了如何在 zend db 模型中使用“distinct"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我已经搜索了很长时间才能让这件事起作用.

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

                  我想知道我如何在 zend db 模型中使用distinct"来使我对用户的关注者的选择独一无二.

                  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.

                  我的数据库模型计算用户的关注者(这里我需要添加'distinct')

                  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;
                      }
                  }
                  

                  这个函数是'class Application_Model_DbTable_Followers extends Zend_Db_Table_Abstract'的一部分

                  This function is part of 'class Application_Model_DbTable_Followers extends Zend_Db_Table_Abstract'

                  我的表结构

                  • id
                  • article_id//'user_id' 所写文章的 ID.
                  • user_id//文章所有者的 user_id
                  • follower_id//关注这篇文章的成员
                  • date//关注日期

                  'user_id'可以写各种文章,关注者可以关注同一作者的各种文章.我想让一个独特的追随者计数.举个例子,我想要什么,如果一个追随者关注一位作家的 8 篇文章,它必须与计数中的1"进行比较.

                  '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.

                  亲切的问候,

                  尼基

                  推荐答案

                  Using distinct:

                  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;
                  }
                  

                  在有问题的编辑后获取用户的关注者数量.您实际上需要使用 group NOT distinct.我已经测试了以下查询工作来获取要 count()ed 的数据,

                  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

                  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;
                  }
                  

                  这篇关于如何在 zend db 模型中使用“distinct"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                  Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
                1. <small id='aNVd8'></small><noframes id='aNVd8'>

                2. <tfoot id='aNVd8'></tfoot>

                      <bdo id='aNVd8'></bdo><ul id='aNVd8'></ul>

                      <i id='aNVd8'><tr id='aNVd8'><dt id='aNVd8'><q id='aNVd8'><span id='aNVd8'><b id='aNVd8'><form id='aNVd8'><ins id='aNVd8'></ins><ul id='aNVd8'></ul><sub id='aNVd8'></sub></form><legend id='aNVd8'></legend><bdo id='aNVd8'><pre id='aNVd8'><center id='aNVd8'></center></pre></bdo></b><th id='aNVd8'></th></span></q></dt></tr></i><div id='aNVd8'><tfoot id='aNVd8'></tfoot><dl id='aNVd8'><fieldset id='aNVd8'></fieldset></dl></div>
                      <legend id='aNVd8'><style id='aNVd8'><dir id='aNVd8'><q id='aNVd8'></q></dir></style></legend>

                          <tbody id='aNVd8'></tbody>