查询错误从其他表(连接表)获取字段的雕像

时间:2017-04-10 10:47:55

标签: php mysql codeigniter

我有两个表,第一个叫做latestnews,第二个叫做language_latestnews

latestnews有`latestnewsstatus和latestnewsid。 和language_latestnews有latestnewsid

我需要显示唯一的Active latestnewsstatus,这是我在api中的代码

 public function getlatest($select_values = "*", $table_name, $join_on = "", $language_id) {
    $join_table = "language_" . $table_name;
    $result = array();
    $this->db->select($select_values);
    $this->db->from($table_name);

    if ($table_name != "latestnews") {
        $this->db->where($table_name . ".featuredstatus","=", "Yes" );
    }
    $this->db->join($join_table, $table_name . "." . $join_on . "=" . $join_table . "." . $join_on, "left");
    $this->db->where($join_table . ".languageid", $language_id ,'latestnews.latestnewsstatus',"=","Active");
    $this->db->join('language_latestnews', 'language_latestnews.latestnewsid = latestnews.latestnewsid', 'left');
    $this->db->where('latestnewsid.latestnewsstatus', "Active");

    $this->db->limit("1");

    $result = $this->db->get()->result_array();
    return $result;
}

但它给了我数据库错误。你能告诉我这里有什么问题:(

错误是:

  

              

发生数据库错误

              

错误号码:1054

              

'where子句'中的未知列'latestnewsid.latestnewsstatus'

              

SELECT offersofferidoffertitle   来自offers   LEFT JOIN language_offers点击offersofferid = language_offersofferid   LEFT JOIN language_latestnews点击language_latestnewslatestnewsid = latestnewslatestnewsid   在哪里offersfeaturedstatus ='='   和language_offerslanguageid ='1'   和latestnewsidlatestnewsstatus ='有效'    限制1

              

文件名:modules / api / models / Apimodel.php

              

行号:394

1 个答案:

答案 0 :(得分:0)

错误是不言自明的'where子句'中的未知列'latestnewsid.latestnewsstatus'。在您的查询中,latestnewsstatus表中没有名称为latestnewsid的列。因此,请在此处输入正确的列名,然后重试。