Pagination计数错误Cakephp 1.2

时间:2016-09-06 09:04:40

标签: php mysql cakephp pagination cakephp-1.3

我有拍卖出价单(每次拍卖的借方等于1)。我更改了“借记”的查看代码,以显示“拍卖ID”计数。 (你可以看到图片。) 但现在我的分页问题。它必须显示26但你可以看到93。 我希望在图片中显示结果,但要有正确的分页。

这是我的代码

在控制器中:

$this->paginate = array(
    'conditions' => array('Bid.user_id' => $user_id),
    'limit' => 100,
    'order' => array('Bid.created' => 'desc'),
    'contain' => array('Auction' => array('Product'))
);

$this->set('bids', $this->paginate());

在Model中:覆盖paginateCount()

function paginateCount($conditions = null, $recursive = 0, $extra = array()) {
    $sql = "
        SELECT user_id,
               auction_id,
               description,
               debit,
               COUNT( * ) AS my_auct,
               `credit`,
               `created`
          FROM `bids`
         WHERE `user_id` = {$this->User->id}
         GROUP BY auction_id, credit
    ";

    $this->recursive = $recursive;
    $results = $this->query($sql);

    return count($results);
}

如何仅在控制器中修复此问题(不使用paginateCount)并将此查询结果放入View(现在我在View中进行计算)。

提前致谢!

enter image description here

1 个答案:

答案 0 :(得分:0)

我解决了我的问题。这是我在控制器中的代码

$this->paginate = array('conditions' => array('Bid.user_id' => $user_id),'fields' => array('COUNT(auction_id) as my_auct', 'Bid.*'), 'group' => array('Bid.auction_id', 'Bid.credit'), 'limit' => 10000, 'order' => array('Bid.created' => 'desc'), 'contain' => array('Auction' => array('Product')));

我找到了paginateCount函数here并添加到模型中:

public function paginateCount($conditions = null, $recursive = 0, $extra = array()) {
                $conditions = compact('conditions');
                if ($recursive != $this->recursive) {
                    $conditions['recursive'] = $recursive;
                }
                unset( $extra['contain'] );
                $count = $this->find('count', array_merge($conditions, $extra));

                    if (isset($extra['group'])) {
                        $count = $this->getAffectedRows();
                    }

                return $count;
            }

只有我无法在" Credit"列是所有值(当我按auction_id和credit分组时,它只向我显示15和100)。我想在信用栏

中显示所有值

有什么想法吗?