我有两个桌子
Team
Teamid
Teamname
Playingteams
Playingteamsid
Team1 fk(teamid)
Team2 fk(teamid)
Team3 fk(teamid)
Team table
Teamid teamname
1 kkkk
2 jjjj
3 llll
4 gggg
5 aaaa
Playingteam table
Ptid team1 team 2 team 3
1 1 3 5
2 2 4 5
3 1 2 4
我想查看为
参加比赛
Pt id Team 1 Team2 Team3
1 Kkkk Llll Aaaa
2 Jjjj Gggg Aaaa
3 Kkkk Jjjj Gggg
现在,如果我想在表中打印team1 team2 team3名称,我应该怎么做?
我正在使用foreach来打印playteamteam表
Foreach($pt as $row)
{
echo’
<td> ‘.$row->playingteamsid.’ </td>’
<td> ‘.$row->team1.’ </td>’
<td> ‘.$row->team2.’ </td>’
<td> ‘.$row->team3;’ </td>’
}
答案 0 :(得分:0)
在模型中
docker push
在控制器中
$query = $this->db->select('team1','team2','team3')->from('playingteams')->limit(1)->get();
$array = $query->result();
return $array;
您可以使用json_encode()在视图中打印这些值。 要打印表名,请从数组中获取键。
my_team = array();
my_team = array(
'team1' => $array[0]->team1,
'team2' => $array[0]->team2,
'team3' => $array[0]->team3,
);
请注意,这些表名并非来自数据库。我在控制器中分配这些值。如果要从模型中提取这些值,则必须将其用于循环控制器。