Welcome Guest, Not a member yet? Register   Sign In
php-activerecord and 2 foreign keys referring to one table
#2

[eluser]Akinzekeel[/eluser]
I think you just need a JOIN. Also, you should use table aliases and field name aliases because you'll have to join the same table twice. Here's an example (untested):

Code:
$this->db->select( "m.id, ht.name home_team_name, at.name away_team_name" );
$this->db->join( "teams ht", "ht.id = home_team_id" );
$this->db->join( "teams at", "at.id = away_team_id" );
$result = $this->db->get( "matches m" )->result();

foreach( $result as $match )
    echo "Match " . $match->id . ": " . $match->home_team_name . " VS " . $match->away_team_name;


Messages In This Thread
php-activerecord and 2 foreign keys referring to one table - by El Forum - 03-21-2012, 03:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB