I am trying to create a fixture for two teams in Codeigniter. I have a table for team
TEAM
team_id
team_name
team_logo
I also have a table for fixture.
Fixture
fixture_id
fixture_text
fixture_comp
fixture_type
fixture_level
fixture_date
The relationship between these two tables is many to many which creates a JOIN table which has a composite PK made up from team_id and fixture_id
Team_Fixtures
team_id
fixture_id
I am a beginner to sql and Codeigniter which is the framework I am working with and I am looking to query these tables. I want to get all the information from the fixture table plus the team name and logo from the team table. I am able to query the tables individually and get the information but am wondering how to write a join statement in Codeigniter that will get all the information in the same query.
This is what I use to query the fixture table at the moment.
MODEL
<?php
class Fixture_model extends CI_Model {
public function __construct()
{
parent::__construct();
}
function fixtures()
{
$fixture_level = "Roinn 1B";
//Query the fixture table for every record and row
$results = array();
$this->db->select('fixture_text, fixture_type, fixture_comp, fixture_date, fixture_level');
$this->db->from('fixture');
$this->db->where('fixture_level', $fixture_level );
$query = $this->db->get();
if($query->num_rows() > 0)
{
$results = $query->result();
}
return $results;
}
}
/*End of file fixture_model.php*/
/*Location .application/models/fixture_model.php*/
?>
And in my VIEW
<?php
if (is_array($results))
{
if( !empty($results) )
{
foreach($results as $row)
{
echo '<div class="col-sm-6 col-md-6">';
echo '<div class="thumbnail">';
echo '<tr>';
echo '<h4>';
echo '<td>'.$row->fixture_type.'</td>'."</br></br>";
echo '<td>'.$row->fixture_level.'</td>'."</br></br>";
echo '<td>'.$row->fixture_comp.'</td>'."</br>";
echo '</h4>';
echo '<td>'.$row->fixture_text.'</td>'."</br>";
echo '<td>'.$row->fixture_date.'</td>'."</br></br>";
echo '</tr>';
echo '</div>';
echo '</div>';
}
}
else echo "Not Array";
}
?>
I am trying to create a fixture that will feature the team name and logo from team 1 followed by the fixture details then the team name and logo from team 2
I know its something like this for the JOIN but am not sure what to join on.
$this->db->select('*');
$this->db->from('fixture');
$this->db->join('team', '? = ?');
$query = $this->db->get();
Any help really appreciated