2016-03-01 18 views

回答

0

這裏是你的Demo.php控制器:

class demo_model extends CI_Model 
{ 
    function get_records() 
    { 
     $this->db->select('your tbl columns'); //Ex: u_id,fname,lname 
     $this->db->from('your tbl name'); // tbl_user 
     $this->db->order_by("title", "desc"); //u_id 
     $query = $this->db->get(); 
     return $result = $query->result(); 
    } 
} 

if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class Demo extends CI_Controller { 

    public function __construct(){ 
     parent::__construct(); 
    } 

    $this->load->model('demo_model'); 
    $this->load->helper('url'); 

    function display_content() 
    { 
     $data = array();    
     $data['result'] = $this->demo_model->get_records(); 
     $this->load->view('demo/show_content', $data); 
    } 
} 

您作爲demo_model.php模型

您的視圖文件show_content.php:

<table> 
<tr> 
<th>All Records</th> 

</tr> 
<?php foreach($result as $res): ?> 
<tr><?php echo $res->content; ?></tr> 
<?php endforeach; ?> 
</table> 
?> 

氏s是樣品,現在您必須根據您的需要設置所有參數...

+0

謝謝@kunal我會試試這個 – Whendikz

相關問題