I have a database set up with 2 tables: players and stats for players the PRIMARY KEY is id. for stats the PRIMARY KEY is id, but also has a foreign key of p_id.
I am trying to write s sql statement that will allow me to to return the stats for a certain player dynamically.
Here is what I have. If i change $p_id = 1 or something of that nature then I get the results, however I wish to do this dynamically.
Any help would be appreciated.
public function get_stats_for_player($p_id) {
$this->db->select('*');
$this->db->from('stats');
$this->db->join('players', 'players.id = stats.p_id');
$this->db->where('stats.p_id', $p_id);
$query = $this->db->get();
return $query->result_array();
}