Php Codeigniter:如何为相关表进行嵌套选择
我的数据库中有两个表,一个是“休息室”,另一个是“城市”。它们之间没有明确的联系。我的意思是我没有把“城市id”列在“休息室表”中。我只是从“城市”中选取“名字”一栏,选择它作为“休息室” 我使用的是Codeigniter和DataMapperPHP,所以目前我在lounge.php中的索引函数列出了“CITIES”表中的所有“CITIES”,我有一个名为“search”的列,它是lounge.php中函数名的名称,从那里我很容易说出“where('city','London'))我在伦敦的所有休息室里都有 我的问题是如何使它更好。我的意思是使它只有一个功能“视图”,例如,链接将自动生成,而无需我添加一个新的功能与城市名称时,我必须添加一个新的城市 你知道该怎么做吗 这是在代码中看到它的一个例子:Php Codeigniter:如何为相关表进行嵌套选择,php,mysql,sql,codeigniter,codeigniter-datamapper,Php,Mysql,Sql,Codeigniter,Codeigniter Datamapper,我的数据库中有两个表,一个是“休息室”,另一个是“城市”。它们之间没有明确的联系。我的意思是我没有把“城市id”列在“休息室表”中。我只是从“城市”中选取“名字”一栏,选择它作为“休息室” 我使用的是Codeigniter和DataMapperPHP,所以目前我在lounge.php中的索引函数列出了“CITIES”表中的所有“CITIES”,我有一个名为“search”的列,它是lounge.php中函数名的名称,从那里我很容易说出“where('city','London'))我在伦敦的所有
public function index()
{
$cities = new City_model();
$cities->where('active', '1')->order_by('id', 'ascen')->get();
$recent_cities = array();
foreach ($cities as $city)
{
$single_city = array
(
'id' => $city->id,
'city_name' => $city->city_name,
'search' => $city->search,
);
array_push($recent_cities, $single_city);
}
$data = array
(
'cities' => $recent_cities,
'main_content' => 'templates/city_lounges',
'active_state' => 'lounge',
);
$this->parser->parse('template_main', $data);
}
public function london()
{
$lounges = new Lounge_model();
$lounges->where('city', 'London')->order_by('date_added', 'desc')->get();
$recent_lounges = array();
foreach ($lounges as $lounge)
{
$id = $lounge->id;
$fetch_slug = $lounge->club_slug;
$trimpdate = $lounge->date_added;
$date = explode(" ", $trimpdate);
$single_lounge = array
(
'id' => $lounge->id,
'club_name' => $lounge->club_name,
'club_logo' => $lounge->club_logo,
'facebook_page' => $lounge->facebook_page,
'date_added' => $date[0],
'city' => $lounge->city,
);
array_push($recent_lounges, $single_lounge);
}
$data = array
(
'lounges' => $recent_lounges,
'main_content' => 'templates/content_lounges',
'active_state' => 'lounge',
);
// Parse it to the template
$this->parser->parse('template_main', $data);
}
我已经找到了更好的方法,我在两个表之间建立了一个连接,我使用URI从链接中获取片段,该链接也会进入查询,只选择城市中的休息室
现在问…似乎是个愚蠢的问题。plz添加两个表的表结构