Reputation: 3
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();
}
Upvotes: 0
Views: 808
Reputation: 166
your model function and query are correct.. how you are calling this function? make sure that you are passing $p_id parameter to the function
eg:-
$p_id = 1;
$players = $this->my_model->get_stats_for_player($p_id);
Upvotes: 3