2012-05-24 47 views
0

我想在zend中使用連接。以下是我的查詢在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'); 

我在tendersupplier表中有UserID。但其捐贈以下錯誤: -

柱未發現:1054未知列「tendersupplier.UserID」在「草案第

+0

它看起來像你'tendersupplier'別名爲'tblsupplier'。 – RockyFord

回答

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'); 
+0

它給錯誤--->缺少Zend_Db_Select :: join()的參數2,它給最後加入的錯誤 – Navdeep

+0

@Nacdeep,是tblsupplier表嗎?我懷疑這是一張桌子,我更新了答案 – palAlaa

+0

是的,它是一張桌子。現在它的賦予錯誤--->未知列'tendersupplier.UserID'在'where子句' – Navdeep

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表連接的值。

+0

其給出錯誤----------未知列'tendersupplier.UserID' – Navdeep

+0

@Navdeep:請重新檢查你是否是使用tblsupplier.UserID'或tendersupplier.UserID。您必須使用tblsupplier.UserID。 – besin

0

看起來你試圖加入2個表格 - >加入,我認爲你不能這樣做。

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

you may also need to alter your select() definition to allow joins

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

這裏是從註釋塊()

/** 
    * 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. 
    */ 

也許嘗試這樣的,而不是東西加入代碼

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

我希望我能正確地閱讀你的意圖,這應該讓你更接近,如果不是所有的方式。 (一個提示,使用較短的別名...)