I have a problem with my class (extend by Zend_Db_Table_Abstract), it returns with only one row each time with a join and select….
I searched on the internet but I found nothing on this “bug”!
class Api_Model_News extends Zend_Db_Table_Abstract
{
protected $_name = 'news';
protected $_primary = 'news_id';
protected $select;
public function init()
{
$this->select = $this->select();
}
public function setTimestamp($timestamp)
{
$this->select
->where('news_timestamp >= ?', $timestamp);
return $this;
}
public function setCategory($id_category)
{
$this->select
->where('bsn_id_category = ?', $id_category);
return $this;
}
public function getNews()
{
$this->select
->from('news')
->joinLeft('business', 'news_id = bsn_id', array());
$data = $this->fetchAll($this->select);
return $data->toArray();
}
}
In another function:
$news = new Api_Model_News();
if ($id_category != NULL)
$news->setCategory($id_category);
if ($last_sync != NULL)
$news->setTimestamp($last_sync);
return $news->getNews();
- When I set
id_categoryand notlast_sync=> Only ONE row - When I set
last_syncand notid_category=> Multiples rows - When I set
last_syncandid_category=> Only ONE row
Why? I suppose it’s because I use bsn_id_category in select but I don’t understand ….
Building on the last answer, try this: