0

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();
}
1
  • you want sql statement instead of this ? question is not properly defined Commented Jun 11, 2012 at 18:57

1 Answer 1

3

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.