0
我在CodeIgniter中只使用此代碼獲取一個特色項目。我想獲得5個不同的特色項目。在CodeIgniter中加載數據
我的模型:
// GET THE FEATURED PRODUCTS
function getMainFeature(){
$data = array();
$this->db->select("id, a_title, a_description, a_image");
$this->db->where('a_featured', true);
$this->db->where('a_status', 'active');
$this->db->order_by("rand()");
$this->db->limit(5);
$Q = $this->db->get('articles');
if($Q->num_rows() >0){
foreach($Q->result_array() as $row){
$data = array(
"id" => $row['id'],
"a_name" => $row['a_title'],
"a_description" => $row['a_description'],
"a_image" => $row['a_image']
);
}
}
$Q->free_result();
return $data;
}
我的控制器:
function index(){
//get featured
$data['mainfeature'] = $this->MArticles->getMainFeature();
$data['main'] = 'template/main/home';
//load data and template
$this->load->vars($data);
$this->load->view('template/main/main_template');
}
我的觀點:
<li>
<?php
foreach($mainfeature as $feat){
echo "<img src='".$mainfeature['a_image']."' border='0' align='left' width='320' height='320'/> \n";
}
?>
</li>