phpmyadmin - Codeigniter get sum of goals a player has made -
i got database. mysql script of it. player can appear more in table want sum of goals player has made.
script:
create table if not exists `spelerswedstrijden` ( `id` int(5) not null auto_increment, `spelerid` int(2) not null, `wedstrijdid` int(5) not null, `goals` int(5) default null, `assisten` int(5) default null, `gelekaarten` int(5) default null, `rodekaarten` int(5) default null, primary key (`id`) )
my model code:
function getgoals($id) { $this->db->where('spelerid', $id); $this->db->from('spelerswedstrijden'); $goals = $this->db->select_sum('goals');; return $goals; }
using code gives me following error: object of class ci_db_mysql_driver not converted string ideas how can fix this? in advance
function getgoals($id) { $this->db->select('count(id) totalgoals'); $this->db->where('spelerid', $id); $this->db->group_by('spelerid'); $goals = $this->db->get('goals');; return $goals->row(); }
in controller access this
$result = $this->mymodel->getgoals($id); echo $result->totalgoals;
Comments
Post a Comment