2008-12-04 33 views

回答

153

你也可以使用它像這樣:

你不需要破滅陣列,以及它的安全

+12

谷歌搜索這個問題,並找到你的解決方案 - 然後意識到我已經upvoted一次。所以,既然我不能再次讚揚你,請把這個評論當作我的讚賞! – leek 2010-04-15 02:07:04

+0

很好,非常感謝:) – 2010-04-29 11:20:09

8

顯然這是超級簡單...愚蠢的我:

$select->where('status_id IN(1,3,4)'); 

:(

+0

是的,沒錯。 – 2008-12-04 06:32:38

1
$completionNo = implode(",",$data); 

$db = Zend_Db_Table_Abstract::getDefaultAdapter(); 
$select = $db->select()->from(array("p"=>PREFIX . "property_master"),array('id','completion_no','total_carpet_area'))->where("p.completion_no IN (?)", $completionNo); 
6

第一個答案可能工作在ZF1,但它不能在Zend框架2工作:

在案例Zend Framework2我發現你必須使用:

$data = array(1,3,4); 
$select->where(array('status_id' => $data)); 

結果:

WHERE `status_id` IN ('1', '3', '4') 

我找不到這個記錄任何地方! ZF文件通常不是最優的。

1

我們可以使用Zend\Db\Sql\Predicate\InZend\Db\Sql\Where做出其中模型內查詢。

$this->status_ids = array(1,3,4); 

// select attributes from db by where in 
$result = $this->select(function (Select $select) { 
    $predicate = new In(); 
    $select->where(
     $predicate->setValueSet($this->status_ids) 
       ->setIdentifier('status_id') 
    ); 
})->toArray();