0

这是我在codeigniter中的代码

模型中

    $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;
       }
      ?>
4

2 回答 2

1

在使用 foreach 之前,请检查$auction_view 它是否为数组。您的结果可能是错误的,因为您的数据库查询可能会失败,或者没有返回任何结果。尝试通过使用来检查它,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;
       }
}
于 2013-10-29T10:31:33.480 回答
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;
}
}
?>
于 2013-10-29T13:30:32.030 回答