2014-07-17 44 views
-1

檢索數據所以我得到錯誤:從MySQL表笨語法錯誤

"Parse error: syntax error, unexpected ';', expecting T_FUNCTION in /application/controllers/c_view_users.php on line 19".

我想不通爲什麼。

這裏是我的控制器:

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

class C_view_users extends CI_controller { 

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

} 

public function index() { 

    $data = array(); 
    $this->load->model('m_users'); 
    //$this->load->library('table'); 
    $data['result'] = $this->m_users->get_contents(); 
    $this->load->view('view_users', $data); 
} 
?> 

和型號:

<?php 
class m_claims extends CI_model { 

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

    //Get CI Instance 
    //$CI = & get_instance(); 
    //$CI->load->model(EASYPHP_CORE_DIR . 'user_auth' , 'user_auth'); 

    //--------------- Table name, caption and controller --------------- 
    $this->tableName = "users"; 
    $this->caption = "Users"; 
    $this->controllerName = "c_view_users"; 
    $this->recordsPerPage = 25; 


    //--------------- Pages and function setup --------------- 
    $this->add = true; 
    $this->update = true; 
    $this->view = true; 
    $this->printView = true; 
    $this->delete = true; 
    $this->allowQuickSearch = true; 


function get_contents() { 
    $this->db->select('*'); 
    $this->db->from('scouts'); 
    $query = $this->db->get(); 
    return $result = $query->result(); 
} 
} 

} 
}?> 

,並查看

<table> 
<tr> 
<th>Content</th> 

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

    </tr> 
<?php endforeach; ?> 
</table> 
<?php 

任何人都可以幫助我們發現在控制器上我的錯誤?我已經嘗試過沒有運氣的消除過程。從這裏,我認爲我的語法看起來不錯。

+0

是你的整個控制器?你在末尾 –

+0

處遺漏了一個右括號'}',顯然我的銳利眼睛並不那麼尖銳。謝謝。 – tkdlax

+0

@tkdlax你已經發布'C_view_users'控制器加載'用戶'模型,並且發佈了'm_claims'模型的代碼。任何關係? –

回答

0

模型改成這樣:

<?php 
    class m_claims extends CI_model { 

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

      //Get CI Instance 
      //$CI = & get_instance(); 
      //$CI->load->model(EASYPHP_CORE_DIR . 'user_auth' , 'user_auth'); 

      //--------------- Table name, caption and controller --------------- 
      $this->tableName = "users"; 
      $this->caption = "Users"; 
      $this->controllerName = "c_view_users"; 
      $this->recordsPerPage = 25; 


      //--------------- Pages and function setup --------------- 
      $this->add = true; 
      $this->update = true; 
      $this->view = true; 
      $this->printView = true; 
      $this->delete = true; 
      $this->allowQuickSearch = true; 
     } 

     function get_contents() { 
      $this->db->select('*'); 
      $this->db->from('scouts'); 
      $query = $this->db->get(); 
      return $result = $query->result(); 
     } 
    } 
?> 
+0

我得到重新格式化,但在語法上真的不一樣嗎?我試過了,仍然得到了引用控制器語法的相同錯誤 – tkdlax