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>