gpt4 book ai didi

php - Codeigniter 多对多错误

转载 作者:行者123 更新时间:2023-11-30 22:43:57 25 4
gpt4 key购买 nike

我有 3 个表 ...

教师、类(class)和instructor_teach

我想显示教师教授的类(class)列表

我一直在使用教程之类的东西来尝试解决这个问题,所以如果我的代码很乱,我深表歉意。

模型...

function getMemberPrograms($id){
$this->db->select('*');
$this->db->from('instructor_teach');
$this->db->join('instructor_teach', 'instructors.id = instructor_teach.instructor_id');
$this->db->join('classes', 'instructor_teach.program_id = classes.id');
$this->db->where('instructor_teach.instructors_id', $id);
return;
}

在 Controller 中,我只有一个 print_r 语句来查看结果是什么,但目前我得到了

Error Number: 1066

Table/alias: 'instructor_teach' non unique

SELECT * FROM (`instructor_teach`, `classes`) JOIN `instructor_teach`
ON `instructors`.`id` = `instructor_teach`.`instructor_id` JOIN
`classes` ON `instructor_teach`.`program_id` = `classes`.`id` WHERE
`instructor_teach`.`instructors_id` = '1'

Filename: C:/wamp/www/fitness/application/models/members_model.php

Line Number: 16

我想要的是一个数组,其中包含讲师所教类(class)的所有信息

老师1教1类,2类

数组会返回

类 1.name类 1.描述

类 2.name类2.描述

等..

我希望这是有道理的,因为我还在接受这个

非常感谢乔

最佳答案

我认为您正在将表 instructor_teach 加入到它自己 instructor_teach

看看:

$this->db->from('instructor_teach');
$this->db->join('instructor_teach', 'instructors.id = instructor_teach.instructor_id');

我认为应该是:

$this->db->from('instructor_teach');
$this->db->join('instructors', 'instructors.id = instructor_teach.instructor_id');

:)

关于php - Codeigniter 多对多错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30208774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com