如何使用 mysql codeigniter 对两个表使用选择查询

我有两个表usersemployers在 mysql 中,我只想同时从两个表中获取所有记录。

我如何使用 codeigniter 做到这一点?


慕码人2483693
浏览 123回答 2
2回答

白猪掌柜的

根据您的评论,您在两个表之间没有关系,因此您可以像这样交叉联接一样获取数据:$this->db->select('users.*,employers.*'); $this->db->from('users,employers');$query = $this->db->get();return $query->result();如果你想使用LIKE子句,那么你可以添加:$this->db->like('users.entity', $search_keyword_here, "both"); // here both means '%your keyword%'$this->db->or_like('users.skills', $search_keyword_here, "both"); // here both means '%your keyword%'您也可以将 or_like 用于雇主表。请注意,当我们使用交叉连接时,它会产生类似的结果 (users no of rows *employers no of rows)
打开App,查看更多内容
随时随地看视频慕课网APP