user
和address
。我在zend中加入他们:
$table = new Model_User_DbTable();
$select = $table->select();
$select->setIntegrityCheck( false );
$select->join( 'address', 'address.id = user.address_id', array( 'city' => 'address.city' ) );
$row = $table->fetchAll( $select );
return $row;
但是上面的查询是从地址返回所有地址,而不是从用户表返回数据。当我删除$select->join( 'address', 'address.id = user.address_id', array( 'city' => 'address.city' ) );
时,它只显示用户表数据。
如何获取两个表的数据?
由于
答案 0 :(得分:3)
未测试:
$table = new Model_User_DbTable();
$resultSet = $table->fetchAll($table->select()
->setIntegrityCheck(false)
->from(array('u'=>'user'))
->join(array('a'=>'address'), 'u.address_id = a.id', array('city'=>'address_city'))
);
答案 1 :(得分:1)
尝试使用
$select = $table->select(Zend_Db_Table::SELECT_WITH_FROM_PART);