2012-06-20 23 views
0

Conider這個簡單的查詢:掌握連接結果的計數,在活動記錄

$this->db->join('bids','bids.bid_for = request_quote.quoteid','left'); 

有什麼辦法可以改變它,所以不是加盟的結果,這反而會參加所有的COUNT出價找到?

我可以在普通的SQL重寫這一點,但它是更大的查詢,這我不想在SQL

回答

0

艱難的一個重寫的一部分。我已經看過CI的源代碼,並且我沒有看到「黑客」。 也許你可以使用這個CI的方法:

$this->db->count_all_results(); 
+0

你會看到,只是計算我從主要查詢中得到的所有結果,它不會關心連接結果,如果你知道我的意思。 – vgaldikas

0

好瞎搞了幾個小時後,我得到它的工作,所以生病股吧,以防萬一有人再需要它:

public function getAllJobsByUserId($userid){ 
     $this->db->select('quoteid')->select('quoteby')->select('country_from') 
    ->select('country_to')->select('city_from')->select('city_to') 
    ->select('countries.country_name, countries_to.country_name AS  country_name_to') 
     ->select('COUNT(\'bids.bid_id\') as bid_count'); 
     $this->db->from('request_quote'); 
     $this->db->where('quoteby',$userid); 
     $this->db->join('countries','countries.country_id = request_quote.country_from'); 
     $this->db->join('countries as countries_to','countries_to.country_id = request_quote.country_to'); 
     $this->db->join('bids as bid_count','bid_count.bid_for = request_quote.quoteid','outter'); 
     $query=$this->db->get(); 
    return $query->result(); 
    } 

這似乎上班。但仍然會生病,可能會寫更直接的SQL中更復雜的查詢:)

+0

確實沒有按預期工作。它只會返回一個結果。 – vgaldikas