Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Zend框架leftJoin_Php_Zend Framework_Left Join - Fatal编程技术网

Php Zend框架leftJoin

Php Zend框架leftJoin,php,zend-framework,left-join,Php,Zend Framework,Left Join,这是不起作用的代码 $select = $tariffsTable->select(Zend_Db_Table_Abstract::SELECT_WITHOUT_FROM_PART) ->from('tariff', null) ->where('id = ?', $this->id) ->joinLeft('characteri

这是不起作用的代码

$select = $tariffsTable->select(Zend_Db_Table_Abstract::SELECT_WITHOUT_FROM_PART)
                       ->from('tariff', null)
                       ->where('id = ?', $this->id)
                       ->joinLeft('characteristic_value',
                                  'characteristic_value.tariff_id = id',
                                   array('value_' . $locale, 'characteristic_id'))

                       ->joinLeft('characteristic',
                                  'id = characteristic_value.characteristic_id',
                                  array('name_' . $locale, 'alias'));

$select->setIntegrityCheck(false);
$tariffCharacteristics = $tariffsTable->fetchAll($select)->toArray();
谢谢你的帮助!我已经解决了这个问题。以下是工作代码:

    $select = $tariffsTable->select(Zend_Db_Table_Abstract::SELECT_WITHOUT_FROM_PART)
                             ->from('tariff', null)

                             ->joinLeft( array('characteristic_value'),
                                        'characteristic_value.tariff_id = tariff.id',
                                        array('value_' . $locale))

                             ->joinLeft(array('characteristic'),
                                        'characteristic.id = characteristic_value.characteristic_id',
                                        array('name_' . $locale, 'alias'))
                             ->where('tariff.id = ?', $this->id);

    $select->setIntegrityCheck(false);

这是因为您正在使用
WHERE
和/或
LEFT JOIN on
子句上的
id
列,而您尝试加入的两个表中都应该存在id列

您需要指定在这两种情况下都应使用哪个id

例如characteristic.id或characteristic_value.id或tarriff.id

通过将数组用作
from()
joinLeft()
方法的参数,可以使用别名

$select->from(array('t' => 'tarriff'))
    ->where('t.id = ?', $this->id);