0

我想在zend中使用连接。以下是我的查询

 $select = $this->_db->select()
 ->from(array('evaluationcriteria' => 'procurement_tbltenderevaluationcriteria'),
 array('ScoringCriteriaID','ScoringCriteriaWeight'))
 ->join(array('scoringcriteria' => 'procurement_tbltenderscoringcriteria'),
                               'scoringcriteria.    TenderId=evaluationcriteria.TenderId')
 ->join(array('tenderapplications' => 'procurement_tbltenderapplications','tendersupplier' => 'tblsupplier'),
                               'tenderapplications. TenderInvitationContractorID=tendersupplier.UserID');

我在招标供应商表中有用户 ID。但它给出以下错误: -

未找到列:1054 'on 子句中的未知列'tendersupplier.UserID'

4

3 回答 3

0

where 条件不是按照您的方式编写的。

我不认为 tblsupplier 是一个表,那么它应该在一个数组中

此代码未经测试!

   $select = $this->_db->select()
   ->from(array('evaluationcriteria' => 'procurement_tbltenderevaluationcriteria'),
    array('ScoringCriteriaID','ScoringCriteriaWeight'))
   ->join(array('scoringcriteria' => 'procurement_tbltenderscoringcriteria'),
                           'scoringcriteria.    TenderId=evaluationcriteria.TenderId')
    ->join(array('tenderapplications' =>  'procurement_tbltenderapplications'), array('tendersupplier' => 'tblsupplier'))
    ->where('tenderapplications. TenderInvitationContractorID=tendersupplier.UserID');
于 2012-05-24T08:43:26.377 回答
0

我认为在同一个连接数组中包含多个故事不是正确的方法。试试这样的代码..

->from(array('evaluationcriteria' => 'procurement_tbltenderevaluationcriteria'),
       array('ScoringCriteriaID','ScoringCriteriaWeight'))
->join(array('scoringcriteria' => 'procurement_tbltenderscoringcriteria'),
      'scoringcriteria.    TenderId=evaluationcriteria.TenderId')
      'scoringcriteria.    TenderId=evaluationcriteria.TenderId')
->join(array('tenderapplications' => 'procurement_tbltenderapplications'),
      'tenderapplications.TenderInvitationContractorID=tblsupplier.UserID');

我不确定您是否也打算加入 tblsupplier 表中的值。

于 2012-05-24T08:52:23.480 回答
0

看起来您正在尝试将 2 个表合二为一-> 加入,我认为您不能这样做。

从 Zend_Db_Select() 加入代码

/**
     * Adds a JOIN table and columns to the query.
     *
     * The $name and $cols parameters follow the same logic
     * as described in the from() method.
     *
     * @param  array|string|Zend_Db_Expr $name The table name.
     * @param  string $cond Join on this condition.
     * @param  array|string $cols The columns to select from the joined table.
     * @param  string $schema The database name to specify, if any.
     * @return Zend_Db_Select This Zend_Db_Select object.
     */
    public function join($name, $cond, $cols = self::SQL_WILDCARD, $schema = null)
    {
        return $this->joinInner($name, $cond, $cols, $schema);
    }

这是 from() 的注释块

/**
     * Adds a FROM table and optional columns to the query.
     *
     * The first parameter $name can be a simple string, in which case the
     * correlation name is generated automatically.  If you want to specify
     * the correlation name, the first parameter must be an associative
     * array in which the key is the correlation name, and the value is
     * the physical table name.  For example, array('alias' => 'table').
     * The correlation name is prepended to all columns fetched for this
     * table.
     *
     * The second parameter can be a single string or Zend_Db_Expr object,
     * or else an array of strings or Zend_Db_Expr objects.
     *
     * The first parameter can be null or an empty string, in which case
     * no correlation name is generated or prepended to the columns named
     * in the second parameter.
     *
     * @param  array|string|Zend_Db_Expr $name The table name or an associative array
     *                                         relating correlation name to table name.
     * @param  array|string|Zend_Db_Expr $cols The columns to select from this table.
     * @param  string $schema The schema name to specify, if any.
     * @return Zend_Db_Select This Zend_Db_Select object.
     */

也许尝试这样的事情:

 $select = $this->_db->select()
 //FROM table procurement_tbltenderevaluationcriteria AS evaluationcriteria, SELECT FROM
 //COLUMNS ScoringCriteriaID and ScoringCriteriaWeight
 ->from(array('evaluationcriteria' => 'procurement_tbltenderevaluationcriteria'),
 array('ScoringCriteriaID','ScoringCriteriaWeight'))
 //JOIN TABLE procurement_tbltenderscoringcriteria AS scoringcriteria WHERE 
 //TenderId FROM TABLE scoringcriteria == TenderId FROM TABLE evaluationcriteria
 ->join(array('scoringcriteria' => 'procurement_tbltenderscoringcriteria'),
                 'scoringcriteria.TenderId=evaluationcriteria.TenderId')
 //JOIN TABLE procurement_tbltenderapplications AS tenderapplications
 ->join(array('tenderapplications' => 'procurement_tbltenderapplications'))
 //JOIN TABLE tblsupplier AS tendersupplier WHERE TenderInvitationContractorID FROM TABLE 
 // tenderapplications == UserID FROM TABLE tendersupplier
 ->join(array('tendersupplier' => 'tblsupplier'),
   'tenderapplications.TenderInvitationContractorID=tendersupplier.UserID');

您可能还需要更改您的 select() 定义以允许连接

//this will lock the tables to prevent data corruption
$this->_db->select(Zend_Db_Table::SELECT_WITHOUT_FROM_PART)->setIntegrityCheck(FALSE);

我希望我正确地阅读了您的意图,如果不是一直到那里,这应该会让您更接近。(一个提示,使用较短的别名......)

于 2012-05-24T13:01:53.750 回答