分页计数错误 Cakephp 1.2
Pagination count wrong Cakephp 1.2
我有拍卖出价清单(每次拍卖的借方等于 1)。我更改了 "Debit" 的查看代码以显示 "Auction 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());
在模型中:覆盖 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)并将这个查询结果放入视图(现在我在视图中进行计算)。
提前致谢!
我解决了我的问题。这是我在控制器中的代码
$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 和信用分组时,它只显示一个 15 和 100)。我想在信用栏中显示所有值
有什么想法吗?
我有拍卖出价清单(每次拍卖的借方等于 1)。我更改了 "Debit" 的查看代码以显示 "Auction 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());
在模型中:覆盖 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)并将这个查询结果放入视图(现在我在视图中进行计算)。
提前致谢!
我解决了我的问题。这是我在控制器中的代码
$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 和信用分组时,它只显示一个 15 和 100)。我想在信用栏中显示所有值
有什么想法吗?