2013-03-30 19 views
0

上我想使用的foreach的觀點,但與ID的條件我從mypost我想在我的代碼點火器使用的foreach,但我使用的(ID)conditione和我的其他conditione

模型

public function get_rows($id= FALSE) 
     { 
      if ($id === FALSE) 
      { 
      $query = $this->db->get('table1'); 
      return $query->result_array(); 
      $config['per_page']; 
        $this->uri->segment(3); 
      } 
     $query = $this->db->get_where('table1', array('id'=> $id,'type'=> 2)); 
      return $query->row_array(); 
      } 

控制器

public function index($id){  
     $data['rows'] = $this->model->get_rows($id); 
     if (empty($data['rows'])) 
     { 
     show_404(); 
     } 
     $data['id'] = $data['rows']['id']; 
     $this->load->view('view', $data); 

    } 

查看

<?php foreach ($rows as $row): ?> 
    <li><?php echo $row->title; ?></li> 
<?php endforeach; ?> 

在這裏,我想用每一個對我的看法,但用(ID)我從後獲得的條件和設置我的自我

感謝提前... rafiq__

回答

0

鑑於使用$row['title'];沒有$row->title;

查看

<?php foreach ($rows as $row): ?> 
    <li><?php echo $row['title']; ?></li> 
<?php endforeach; ?> 

,並可能是你需要在你的模型來更改return $query->row_array();return $query->result_array();

型號

public function get_rows($id = 0){ 

    if ($id > 0){ 
     $this->db->where(array('id'=> $id,'type'=> 2)); 
    } 

    return $this->db->get('table1')->result_array(); 
} 
+0

它列出我的所有行利己獲得條件 codition就像:: ** ** ID得到卻又** **類型設置我selef 仍然列出所有行 – rafiq

+0

@rafiq:檢查編輯模型代碼 – mrsrinivas

+0

非常感謝它的工作 – rafiq

相關問題