【发布时间】:2014-02-21 23:28:28
【问题描述】:
这是另一个已部分回答的问题的后续内容,我需要更进一步。
我有一个包含 Team 和 Fixture 表的数据库。这些表之间的关系是多对多的,这会创建一个名为 team has fixture 的 JOIN 表。
team
team_id
team_name
team_logo
fixture
fixture_id
fixture_text
fixture_comp
fixture_type
fixture_level
fixture_date
这两个表之间的关系是多对多的,这会创建一个名为 team_has_fixture 的 JOIN 表,该表具有由 team_id 和 fixture_id 组成的复合 PK
team_has_fixture
team_team_id
fixture_fixture_id
team_team_id2 //added this column to hold the id for second the team in the fixture
我正在尝试创建一个夹具,它使用夹具表中的所有数据和团队表中涉及夹具的两个团队的团队徽标。
例如夹具的布局将如下所示 - 团队 1 徽标 - 夹具详细信息 - 团队 2 徽标
我目前已经到了这个阶段 - 没有团队 2 的徽标
例如夹具的布局将如下所示 - 团队 1 徽标 - 夹具详细信息 -
我想做的是让第二支球队的标志也显示出来。
这是我目前拥有的代码。
型号
<?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('*');
$this->db->from('team_has_fixture');
$this->db->join('team', 'team_has_fixture.team_team_id = team.team_id');
// I tried the line below to get the second logo out
but it just overrides the line above and displays the second logo
instead of the first one but not both
//$this->db->join('team as t', 'team_has_fixture.team_team_id2 = t.team_id');
$this->db->join('fixture', 'team_has_fixture.fixture_fixture_id = fixture.fixture_id');
$query = $this->db->get();
if($query->num_rows() > 0)
{
$results = $query->result();
}
return $results;
}
我的视图中有以下代码来显示从数据库中检索到的结果
查看
<?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>'.'<img src="'."$row->team_logo".'"> '.$row->fixture_text.'</td>'."</br></br>";
echo '<td>'.$row->fixture_level.'</td>'."</br></br>";
echo '<td>'.$row->fixture_comp.'</td>'."</br>";
echo '</h4>';
echo '<td>'.$row->fixture_date.'</td>'."</br></br>";
echo '</tr>';
echo '</div>';
echo '</div>';
}
}
else echo "Not Array";
}
?>
除了我还需要获得第二个团队徽标之外,这一切都有效 - 有什么想法吗??
【问题讨论】:
标签: mysql sql codeigniter join