我有两个几乎相同的功能。
public function getUserAndCommentAndTelephone($paged=NULL)
{
$select = $this->select()->setIntegrityCheck(false)
->from('user',array('name','user_id'))
->join('comment', 'user.user_id = comment.user_id', array('comment_id','text','date'))
->join('telephone', 'telephone.telephone_id = comment.telephone_id', array('number'))
->order(array('comment.comment_id DESC'));
if (null !== $paged) {
$adapter = new Zend_Paginator_Adapter_DbTableSelect($select);
$count = clone $select;
$count->reset(Zend_Db_Select::COLUMNS);
$count->reset(Zend_Db_Select::FROM);
$count->from('comment', new Zend_Db_Expr('COUNT(*) AS `zend_paginator_row_count`'));
$adapter->setRowCount($count);
$paginator = new Zend_Paginator($adapter);
$paginator->setItemCountPerPage(5)
->setCurrentPageNumber((int) $paged);
return $paginator;
}
return $this->fetchAll($select);
另一个在 $select 中有 where 子句。这只是这一个之间的不同。
public function getCommentAndUserByTelephone($number,$paged=null) {
$select = $this->select()->setIntegrityCheck(false)
->from('user',array('name','user_id'))
->join('comment', 'user.user_id = comment.user_id', array('text','comment_id','date'))
->join('telephone', 'telephone.telephone_id = comment.telephone_id', array('number'))
->order(array('comment.comment_id DESC'))
->where('telephone.number = ?', $number);
if (null !== $paged) {
$adapter = new Zend_Paginator_Adapter_DbTableSelect($select);
$count = clone $select;
$count->reset(Zend_Db_Select::COLUMNS);
$count->reset(Zend_Db_Select::FROM);
$count->from('comment', new Zend_Db_Expr('COUNT(*) AS `zend_paginator_row_count`'));
$adapter->setRowCount($count);
$paginator = new Zend_Paginator($adapter);
$paginator->setItemCountPerPage(5)
->setCurrentPageNumber((int) $paged);
return $paginator;
}
return $this->fetchAll($select);
}
并在此与where子句出现错误: Column not found: 1054 Unknown column 'telephone.number' in 'where Clause' when I COMMENT it //->where('telephone.number = ?', $number); 开工。所以这个我的 WHERE 子句有问题。
有人知道如何更改 $select,使用 where 子句使其工作。谢谢