Codeigniter:为什么我得到这个错误,“意外”(',期待标识符(T_STRING)或变量(T_VARIABLE)或'{'或'$'“?

时间:2015-09-02 07:31:01

标签: php codeigniter

  

解析错误:语法错误,意外'(',期待标识符

     

(T_STRING)或变量(T_VARIABLE)或'{'或'$'in   C:\ wamp \ www \ ghostwriter \ application \ models \ addproject_m.php就行了   117

我正在尝试为我的页面创建一个分页,所以我创建了一个函数来获取项目的计数。

function get_projects_count(){
    $this->db->select->('p_id')->from('ghost_projects');
    $query=$this->db->get();
    return $query->num_rows();
}

上面的代码在模型中。

$this->data['projects'] = $this->addproject_m->ongoingprojects(5,$start);
    $this->load->library('pagination');
    $config['base_url'] = base_url().'project/search';
    $config['total_rows'] = $this->addproject_m->get_projects_count();
    $config['per_page'] = 5;
    $this->pagination->initialize($config);
    $data['pages']=$this->pagination->create_links();

以上代码来自控制器。

有人可以帮我解决这个我正面临的问题(对codeigniter来说是新手)。

2 个答案:

答案 0 :(得分:2)

问题在于另外一个' - >'不应该在那里:

$this->db->select->('p_id')->from('ghost_projects'); //right here
$this->db->select('p_id')->from('ghost_projects'); //this is what it should be

错误告诉您,您不能拥有'('之后 - >这是有道理的,因为您必须在以下后面指定方法名称或变量名称。>。

答案 1 :(得分:1)

在您的查询中,您有->附近的select->('p_id')。您也可以将选择查询写为

function get_projects_count(){
    $this->db->select('p_id');
    $this->db->from('ghost_projects'); // there was an extra > before from
    $query=$this->db->get();
    return $query->num_rows();
}