2014-03-31 42 views
0

我有一些日子試圖弄清楚的問題是什麼,但我不能。笨加盟返回錯行(S)

我有這樣的功能:

function gets($status = NULL, $bought = NULL) 
{ 
    $this->db->select('leads.*, clips.id AS clip_id, clips.lead_id AS clip_lead_id, clips.partner_id AS clip_partner_id, clips.type AS clip_type, clips.clip AS clip_clip, clips.price AS clip_price, clips.created_at AS clip_created_at, clips.updated_at AS clip_updated_at, clips.ip_address AS clip_ip_address'); 
    if ($status != FALSE) 
    { 
     $this->db->where('leads.status', $status); 
    } 
    $this->db->from('leads'); 
    if ($bought != FALSE) 
    { 
     $this->db->where('clips.partner_id', $this->session->userdata('partner_id')); 
     $this->db->where('clips.type', '-'); 
     $this->db->join('clips', 'clips.lead_id = leads.id'); 
    } 
    else 
    { 
     $this->db->where('clips.partner_id', $this->session->userdata('partner_id')); 
     $this->db->where('clips.type', '-'); 
     $this->db->join('clips', 'clips.lead_id = leads.id', 'left outer'); 
    } 
    $query = $this->db->get(); 

    if ($query->num_rows() != 0) 
    { 
     return $query->result(); 
    } 
} 

如果我這樣調用$這 - >獲取( '批准')的功能;它應該從引線表那裏有沒有發現在表中剪輯的比賽,其中PARTNER_ID等於當前會話,其中類型是減去返回所有行。

如果我打電話的功能等這樣$這個 - >獲取(「」,「買」);它應該返回找到匹配項的所有行,其條件與上面相同。

我希望你能理解我的代碼和幫助我。

如果您有任何問題,隨時問!

謝謝!

+0

你得到任何錯誤? – aseferov

+0

沒有。我有三排鉛。它應該返回其中的兩個,但它只返回它不應該返回的那個。 – Casperlarsen

+0

哪裏是你的加入表名,你從剪輯表中獲取所有內容並加入到剪輯中,我認爲你還需要加入潛在客戶表 – aseferov

回答

0

我重寫了代碼,這是我得到了什麼工作。

function gets($status = NULL, $bought = NULL) 
{ 
    // Get the rows where the partner has used clips 
    $this->db->where('partner_id', $this->session->userdata('partner_id')); 
    $this->db->where('type', '-'); 
    $query = $this->db->get('clips'); 

    if ($status != FALSE) 
    { 
     if(is_array($status)) 
     { 
      $first = TRUE; 
      foreach($status as $row) 
      { 
       if ($first == TRUE) 
       { 
        $this->db->where('leads.status', $row); 
        $first = FALSE; 
       } 
       else 
       { 
        $this->db->or_where('leads.status', $row); 
       } 
      } 
     } 
     else 
     { 
      $this->db->where('leads.status', $status); 
     } 
    } 

    $bought_array[] = ''; 
    if ($query->num_rows() != 0) 
    { 
     foreach($query->result() as $row2) 
     { 
        // Add the ID's of the bought leads to array 
      $bought_array[] = $row2->lead_id; 
     } 
    } 

    // If bought leads should not be shown in the results 
    if ($bought == FALSE) 
    { 
     $this->db->where_not_in('id', $bought_array); 
    } 
    else // If they should... 
    { 
     $this->db->where_in('id', $bought_array); 
    } 

    $query2 = $this->db->get('leads'); 

    if ($query2->num_rows() != 0) 
    { 
     return $query2->result(); 
    } 
} 
0

我想應該是這樣的

function gets($status = false, $bought = false) 
{ 
    $this->db->select('leads.*, clips.id AS clip_id, clips.lead_id AS clip_lead_id, clips.partner_id AS clip_partner_id, clips.type AS clip_type, clips.clip AS clip_clip, clips.price AS clip_price, clips.created_at AS clip_created_at, clips.updated_at AS clip_updated_at, clips.ip_address AS clip_ip_address'); 
    if ($status) 
    { 
     $this->db->where('leads.status', $status); 
    } 
    if ($bought) 
    { 
     $this->db->where('clips.partner_id', $this->session->userdata('partner_id')); 
     $this->db->where('clips.type', '-'); 
     $this->db->join('clips clips', 'clips.lead_id = leads.id'); 
    } 
    else 
    { 
     $this->db->where('clips.partner_id', $this->session->userdata('partner_id')); 
     $this->db->where('clips.type', '-'); 
     $this->db->join('clips clips', 'clips.lead_id = leads.id', 'left outer'); 
    } 
    $query = $this->db->get('leads leads'); 

    if ($query->num_rows() != 0) 
    { 
     return $query->result(); 
    } 
} 
+0

不工作。表名是「鉛」和「剪輯」。 – Casperlarsen

+0

你得到錯誤或什麼不工作? – aseferov

+0

對不起。不,我沒有得到一個錯誤。但它仍然只是返回它不應該的行。 – Casperlarsen