Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Codeigniter mysql加入不起作用_Mysql_Codeigniter - Fatal编程技术网

Codeigniter mysql加入不起作用

Codeigniter mysql加入不起作用,mysql,codeigniter,Mysql,Codeigniter,我有一个数据库,它有两个表,还有一个搜索关键字,如何连接表,在所有表中进行选择 $this->db->select('*'); $this->db->from('tracks', 'genres'); $this->db->join('genres', 'genres.genreid = tracks.genre_id'); $this->db->or_where('tracks.title', $key); $this->db->o

我有一个数据库,它有两个表,还有一个搜索关键字,如何连接表,在所有表中进行选择

$this->db->select('*');
$this->db->from('tracks', 'genres');
$this->db->join('genres', 'genres.genreid = tracks.genre_id');

$this->db->or_where('tracks.title', $key);
$this->db->or_where('tracks.author', $key);
$this->db->or_where('genres.genreid', $key);
$this->db->order_by('tracks.rate', 'ASC');
$q = $this->db->get();

必须在from中有一个表,在join中有其余的表


$this->db->from'tracks'

使用join语句来完成where子句的工作也是值得的。如果确实进行了联接,然后在何处选择表之间的所有联接,然后在何处应用,但是在联接中使用and,则需要为db做的工作更少

$this->db->select('*');
$this->db->from('tracks');
$this->db->join('genres', 'genres.genreid = tracks.genre_id');
$this->db->where('tracks.title', $key);
$this->db->or_where('tracks.author', $key);
$this->db->or_where('genres.genreid', $key);
$this->db->order_by('tracks.rate', 'ASC');
$q = $this->db->get();

这是正确的使用方法。在FROM子句和JOIN中使用相同的表,这就是问题所在。另一件事是您缺少WHERE子句,只使用了or WHERE。

1您应该第一次使用->WHERE,而不是所有->或\u WHERE;Echo$this->db->last_query&与您试图实现的目标进行比较,然后来编辑您的帖子。