2012-09-08 168 views
-3

在我沒有收到任何回覆之前,我問這個問題,如果這有幫助,我決定重新發布它。我希望我沒有通過重新發布做任何錯誤?Codeigniter邏輯運算符

$total_cost_for_A = $this->admin_model->total_cost_for_A($branch, $department, $date); 
$total_cost_for_B = $this->admin_model->total_cost_for_B($branch, $department, $date); 

變量 $ total_cost_for_A和$ total_cost_for_B持有從模型中的一個MySQL查詢總和返回值。如果沒有找到記錄,則查詢返回false。現在,我正在嘗試執行此操作。

if(($total_cost_for_A === FALSE) && ($total_cost_for_B === FALSE)) 
{ 
    $data['no_record'] = 'No Record Found!'; 
    $this->load->view('admin/bookings', $data); 
} 
else 
{ 
    $this->load->view('admin/summary', $data); 
} 

該測試總是失敗並執行else語句,而不是這個。任何援助將不勝感激。由於

下面是功能

function total_cost_for_A($branch, $department, $date) 
    { 
     if($branch == 'Head Office' && $department == 'Summary') 
     { 
      $select_amount_paid = 'SELECT SUM(total_amount) total_amount FROM graphics_booking AS bk 
      WHERE bk.date = "'.$date.'"'; 
     } 

     $result = $this->db->query($select_amount_paid); 

     if($result->num_rows() > 0) 
     { 
      return $result; 
     } 
     else 
     { 
      return FALSE; 
     } 
    } 


    function total_cost_for_B($branch, $department, $date) 
    { 
     if($branch == 'Head Office' && $department == 'Summary') 
     { 
      $total_LF_amount = 'SELECT SUM(total_amount) total_amount FROM large_format_print 
      WHERE date = "'.$date.'"'; 
     } 

     $result = $this->db->query($total_LF_amount); 

     if($result->num_rows() > 0) 
     { 
      return $result; 
     } 
     else 
     { 
      return FALSE; 
     } 
    } 
+1

是的,你是。耐心一點。 @ dm03514給了一個很好的答案。請解決這個[在其他線程](http://stackoverflow.com/questions/12323539/php-codeigniter-logical-operator)。被標記關閉。 –

+0

有人應該把它取下來。對不起 – sality

回答

0

試圖改變這樣的

$select_amount_paid = 'SELECT SUM(total_amount) total_amount FROM graphics_booking AS bk 
     WHERE date = '.$date;//i assume that date is an colum from graphics_booking 

你錯了「bk.date」你可以直接給它是否在你的表在哪裏條件,也儘量避免在模型中的功能和變量賦值相同的名稱。嘗試改變爲不同。其他代碼看起來不錯

0

沒有當u返回你無法返回的整個,你需要返回一行

,所以你需要在你的模型來做爲:

function total_cost_for_A($branch, $department, $date) 
    { 
     if($branch == 'Head Office' && $department == 'Summary') 
     { 
      $select_amount_paid = 'SELECT SUM(total_amount) total_amount FROM graphics_booking AS bk 
      WHERE bk.date = "'.$date.'"'; 
     } 

     $result = $this->db->query($select_amount_paid); 

     if($result->num_rows() > 0) 
     { 
      return $result->row();  // you missed out here 
     } 
     else 
     { 
      return FALSE; 
     } 
    } 

相同的total_cost_for_B()

+0

@sality即時通訊希望你已經在MySQL運行查詢和它的運行良好 –

+0

謝謝,我會嘗試,並在這裏報告 – sality