2011-08-15 20 views
0

我在我的DB上有4個表格; 商家,pay_method,花費ans transaction_type。嘗試使用Zend(SE)連接執行查詢

它們都有一個id和一個標題,除了花費(花費了其他字段的外鍵以及其他字段,如user_id,comment,...)。

我嘗試擁有一個唯一user_id的所有表的所有信息!

的執行它,我嘗試了一些測試,不運行:

public function getSpendingsForUser($userid) 
{ 
    $mercTable = Engine_Api::_()->getDbTable('merchants', 'spendings'); 
    $mercName = $mercTable->info('name'); 

    $table = Engine_Api::_()->getDbTable('spendings', 'spendings'); 
    $spendName = $table->info('name'); 

    $select = $table->fetchAll(
     $table->select() 
     ->joinLeft($mercName, "$mercName.merchant_id = $spendName.merchant_id", NULL) 
     ->where('user_id = ?', $userid) 
     ->group('spending_id') 
     ); 
    return $select; 

} 

一個視圖中的文件:

foreach($this->spendings as $s) { 
     var_dump($s->comment); 
} 

我怎樣才能使連接正確掌握所有來自user_id的信息?

非常感謝!

回答

1

你應該定義不運行來幫助我們來幫助你。但我可以告訴你,你可能需要->setIntegrityCheck(false);

$select = $table->fetchAll(
     $table->select() 
     ->setIntegrityCheck(false); 
     ->joinLeft($mercName, "$mercName.merchant_id = $spendName.merchant_id", NULL) 
     ->where('user_id = ?', $userid) 
     ->group('spending_id') 
     ); 

加入之前。

+0

好的我會試試這個;-) – clement

+0

@clement它工作嗎? – Iznogood

+0

它更好用;-)謝謝 – clement