PHP关系查询

PHP关系查询,php,codeigniter,relationship,Php,Codeigniter,Relationship,我使用的是PHP和jamierumbelow/codeigniter基本模型 我有两张桌子 Table 1: Class classId classStd ----------------------- 1 Prep 3 NUR 4 STD-1 5 STD-2 Table2: Section sectionId classId section sectionName ----------------------------

我使用的是PHP和jamierumbelow/codeigniter基本模型 我有两张桌子

Table 1: Class classId classStd ----------------------- 1 Prep 3 NUR 4 STD-1 5 STD-2 Table2: Section sectionId classId section sectionName --------------------------------------------------- 5 1 A rose 6 1 B red 7 1 C green 8 3 A ROME 9 3 B PARIS }

返回以下响应

[ {"sectionId":"5","classId":"1","section":"A","sectionName":"rose","class":{"classId":"1","classStd":"Prep"}}, {"sectionId":"6","classId":"1","section":"B","sectionName":"red","class":{"classId":"1","classStd":"Prep"}}, {"sectionId":"7","classId":"1","section":"C","sectionName":"green","class":{"classId":"1","classStd":"Prep"}}, {"sectionId":"8","classId":"3","section":"A","sectionName":"ROME","class":{"classId":"3","classStd":"NUR"}}, {"sectionId":"9","classId":"3","section":"B","sectionName":"PARIS","class":{"classId":"3","classStd":"NUR"}} ] [ {“sectionId”:“5”,“classId”:“1”,“section”:“A”,“sectionName”:“rose”,“class”:{“classId”:“1”,“classStd”:“Prep”}, {“sectionId”:“6”,“classId”:“1”,“section”:“B”,“sectionName”:“red”,“class”:{“classId”:“1”,“classStd”:“Prep”}, {“sectionId”:“7”,“classId”:“1”,“section”:“C”,“sectionName”:“绿色”,“类”:{“classId”:“1”,“classStd”:“Prep”}, {“sectionId”:“8”,“classId”:“3”,“section”:“A”,“sectionName”:“ROME”,“class”:{“classId”:“3”,“classStd”:“NUR”}, {“sectionId”:“9”,“classId”:“3”,“section”:“B”,“sectionName”:“PARIS”,“class”:{“classId”:“3”,“classStd”:“NUR”}} ]
如何仅获取特定记录,例如“classId=1”

使用
get\u many\u by
方法:

$pages = $this->Model_section->with('class')->get_many_by('classId',1);

或者,您可以执行以下操作:创建一个数据库查询,使用一个连接获取所需的所有信息,然后按groupID对结果进行分组。
$pages=$this->Model_section->with('class')->get_many_by('classId',1)?谢谢,它能工作。是否有任何方法可以获取特定字段,如选择字段1,字段2,而不是选择*尝试
$this->Model\u section->\u database->select('field1,field2')
。不,这不起作用。我使用了Model_section->下拉菜单('sectionId','classId');但是我不能触发->with('class')->get\u many\u by('classId',3);使用itHmm…它应该可以工作:
$this->Model_section->\u database->select('sectionId')$pages=$this->Model_section->get_all()确定。我想把classId:“1”从“类”{“classId:“1”,“classStd:“Prep”}中去掉。这是我的分区表。我的响应行是{“sectionId:“5”,“classId:“1”,“section:“A”,“sectionName:“rose”,“class:{“classId:“1”,“classStd:“Prep”}例如,从class_master a、section_master b中选择a.sectionId、a.sectionName、b.classStd,其中a.classId=b.sectionId和b.classId=1
$pages = $this->Model_section->with('class')->get_many_by('classId',1);