SQL Zend Framework Db 选择连接表帮助

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1270125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 03:11:21  来源:igfitidea点击:

Zend Framework Db Select Join table help

sqlzend-frameworkselectjoinzend-db

提问by tester2001

I have this query:

我有这个查询:


SELECT g.title, g.asin, g.platform_id, r.rank
        FROM games g
        INNER JOIN ranks r ON ( g.id = r.game_id )
        ORDER BY r.rank DESC
        LIMIT 5`

Now, this is my JOIN using Zend_Db_Selectbut it gives me array error

现在,这是我的 JOIN 使用,Zend_Db_Select但它给了我数组错误


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

Anyone know what I could be doing wrong? I want to get all the columns in 'games' to show and the 'rank' column in the ranks table.

有谁知道我可能做错了什么?我想显示“游戏”中的所有列以及排名表中的“排名”列。

回答by polygone

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);

回答by Kid

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!

祝你好运!

回答by Bill Karwin

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;

回答by Kropek

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 :)

这工作正常:)