Zend Framework Db Select Join table help

大城市里の小女人 提交于 2019-11-30 21:34:24

I am going to assume you've solved this, but it would be nice to leave the answer for others.

Add this below the instantiation of the select object.

$query->setIntegrityCheck(false);

You could also type fewer characters....

$query = $this->select()
              ->from(array('g' => 'games'), array('title', 'asin', 'platform_id'))
              ->join(array('r' => 'ranks'), 'g.id = r.game_id', array('rank'))
              ->order('r.rank DESC')
              ->limit($top);
return $this->fetchAll($query);

Good luck!

Here's how I'd write it:

$query = $this->select();
$query->from(array('g' => 'games'), array('title', 'asin', 'platform_id'));
$query->join(array('r' => 'ranks'), 'g.id = r.game_id', array('rank'));
$query->order('r.rank DESC');
$query->limit($top);
$resultRows = $this->fetchAll($query);
return $resultRows;

Other example:

select n.content, n.date, u.mail 
from notes n, users u
where n.id_us=u.id and reminder=current_date

$query = $this->select()
    ->from(array('n'=>'notes'), 
      array('content', 'date'))
    ->join(array('u'=>'users'), 'n.id_us=u.id and n.reminder=current_date',
      array('mail'))
    ->setIntegrityCheck(false);
return $this->fetchAll($query);

That's work fine :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!