【问题标题】:unable to fetch record through join in codeigniter无法通过加入 codeigniter 获取记录
【发布时间】:2017-09-08 17:12:35
【问题描述】:

我只是受够了收到以下错误消息。

错误号:1146 表'codeign.lc_64'不存在 选择 * 从 (lc_question, lc_64, lc_1, lc_district) 加入 lc_answers ON lc_question.id_question = lc_answers.id_question 文件名:D:/xampp/htdocs/CI/test2/system/database/DB_driver.php 行号:691

这里是我的查询。

//assume i have this value $dist = 64, $type = 1, $dist_name =Delhi

$this->db->select('*');
$this->db->from('lc_question');
$this->db->join('lc_answers', 'lc_question.id_question = lc_answers.id_question');
$query = $this->db->get_where(array('lc_answers.id_district' => $dist, 'a.question_type' => $type, 'a.question_level' =>$dist_name));
return $query->row_array();

【问题讨论】:

  • 好的,您有什么具体问题吗?或者你只是想让我们知道你很生气?如果您要解决此问题,从错误消息中可以明显看出表 codeign.lc_64 不存在

标签: php mysql codeigniter join


【解决方案1】:

get_where() 第一个参数需要一个表名。由于您已经使用$this->db->from('lc_question'); 定义了表格,我建议您改用where()

这里我使用了方法链和get('table_name') 方法。不需要db->select('*'),因为$this->db->get('mytable'); 产生“SELECT * FROM mytable”。

$query = $this->db
    ->join('lc_answers', 'lc_question.id_question = lc_answers.id_question')
    ->where(array('lc_answers.id_district' => $dist, 'a.question_type' => $type, 'a.question_level' =>$dist_name))
    ->get('lc_question');
return $query->row_array();

您可能仍然有问题,因为我没有看到别名“a”(如'a.question_type')的定义位置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-07
    • 2018-05-22
    • 2019-09-17
    • 1970-01-01
    • 2014-09-09
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    相关资源
    最近更新 更多