2013-10-29 235 views
0

這裏是我的笨代碼無效參數

在結構模型

$where = "is_display ='Yes' AND start_date < '{$current_time}' AND end_date >    
      '{$current_time}' AND status = 'Live' AND id NOT IN (SELECT id FROM (emts_auction)       
      WHERE is_display = 'Yes' AND quantity =1 AND sold_qty >0  
      AND last_auc_ending_time < '{$current_time}')"; 

    $this->db->select('*'); 
    $this->db->from('auction'); 
    $this->db->where($where);  
    $this->db->order_by("id", "desc"); 
    $query = $this->db->get(); 
    $data = $query->result(); 
     $query->free_result(); 
     return $data; 

鑑於

<?php foreach($auction_view as $auction) 
     { 
     echo $auction->name; 
     echo $auction->price; 
     echo $auction->bid_fee; 
     } 
     ?> 
+0

檢查結果查詢,可能是使用var_dump()或print_r() –

+0

'$ auction_view'不是數組所有。 – user2092317

+0

這意味着沒有記錄匹配,結果爲空 –

回答

1

請檢查$auction_view如果是一個數組或不使用foreach之前。您的結果可能是錯誤的,因爲您的數據庫查詢可能失敗,或者沒有返回結果。嘗試使用is_array檢查,如果它,或者你可以做檢查,如果它不是空if(!empty($auction_view))

if (is_array($auction_view)) 
{ 
    foreach($auction_view as $auction) 
     { 
     echo $auction->name; 
     echo $auction->price; 
     echo $auction->bid_fee; 
     } 
} 
+1

$ auction_view是一個數組,我在控制器中定義,,,,,我猜我的數據庫查詢是錯誤的地方部分,並返回null!不管怎樣,謝謝!!! – user2902928

0

在模型

where = "is_display ='Yes' AND start_date < '{$current_time}' AND end_date >    
'{$current_time}' AND status = 'Live' AND id NOT IN (SELECT id FROM (emts_auction)       
WHERE is_display = 'Yes' AND quantity =1 AND sold_qty >0  
AND last_auc_ending_time < '{$current_time}')"; 
$this->db->select('*'); 
$this->db->from('auction'); 
$this->db->where($where);  
$this->db->order_by("id", "desc"); 
$query = $this->db->get(); 
if($quer->num_rows() < 0){return $query->result(); 
} 
return ''; 

鑑於

<?php 
if(!empty($auction_view)){ 
foreach($auction_view as $auction) 
{ 
echo $auction->name; 
echo $auction->price; 
echo $auction->bid_fee; 
} 
} 
?>