Zend Framework Db Choose Connect Table

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_Select, but it gives me an array error


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

Does anyone know what I can do wrong? I want all the columns in the "games" to be displayed and the column "rank" in the rank table.

+5
source share
4 answers

I am going to suggest that you have solved this, but it would be nice to leave an answer for others.

Add this under the creation of the selection object.

$query->setIntegrityCheck(false);
+10
source

You can also enter 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

+5
source

:

$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;
0

:

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

:)

0

All Articles