我有两个表,我试图获得连接结果,但这是我在 var_dump() 上得到的结果;
object(CI_DB_mysql_result)#20 (8) { ["conn_id"]=> resource(29) of type (mysql link persistent) ["result_id"]=> resource(39) of type (mysql result) ["result_array"]=> array(0) { } ["result_object"]=> array(0) { } ["custom_result_object"]=> array(0) { } ["current_row"]=> int(0) ["num_rows"]=> int(3) ["row_data"]=> NULL }
我的表结构是
表名:bands 字段:bands_ref,名称
然后我有另一个表,其中包含艺术家 ID 和乐队 ID(这就是我将乐队与艺术家相关联的方式),我需要保持这种方式,因为艺术家可能在其他 2 个乐队中
表名:artist_bands 字段:artist_id, band_id
最后艺术家表如下:
表名:艺术家 字段:姓名、artist_ref
所以我在这里所做的是,列出艺术家关联的所有乐队。但我认为我犯了一个我看不到的错误。所有其他数据都在我的编辑功能中完美通过,我没有收到任何关于我的 View 或 Controller 的错误,但这是我在我的模型中所做的,这可能会有所帮助
请注意,我的变量已传递给模型,并为艺术家表的其余部分返回结果 - 它是唯一不起作用的 JOIN。
public function get_my_band($artist_ref) {
$this->db->select('*'); $this->db->from('bands'); $this->db->join('artist_bands','artist_bands.band_id = bands.bands_ref'); $this->db->where('artist_bands.artist_id', $artist_ref); $query = $this->db->get(); return $query;
}
如有任何帮助和建议,我们将不胜感激。
谢谢
最佳答案
您似乎没有运行查询。你只是把它框起来了。
public function get_my_band($artist_ref) {
$this->db->select('*');
$this->db->from('bands');
$this->db->join('artist_bands','artist_bands.band_id = bands.bands_ref');
$this->db->where('artist_bands.artist_id', $artist_ref);
return $this->db->get()->result_array();
}
关于php - 合并表的 Codeigniter JOIN 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25144481/