分析错误:语法错误,意外的"(",应为标识符
中的(T_STRING(或变量(T_variable(或"{"或"$"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();
上面的代码来自控制器。
有人能帮我解决我面临的这个错误吗(代码点火器新手(。
问题出现在1个不应该存在的额外"->'中:
$this->db->select->('p_id')->from('ghost_projects'); //right here
$this->db->select('p_id')->from('ghost_projects'); //this is what it should be
错误告诉您不能在->之后有"(",这是有意义的,因为您必须在->之后用乙醚指定方法名或变量名。
在您的查询中,您在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();
}