我希望显示 SQL 请求的结果,但我的代码返回了一个我无法解决的错误。如果有人能帮助我,我将不胜感激。
我正在使用 Codeigniter。
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Dropdown extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$data['title']='Dependent Dropdown List';
$data['page']='index';
$data['MANUFACTURERS'] = $this->book_model->get_author();
$this->load->view('index', $data);
}
public function ctest()
{
$data['MODELS'] = $this->book_model->test();
$this->load->view('ajax_get_book',$data);
}
}
?>
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class book_model extends CI_Model {
function __construct(){
// Call the Model constructor
parent::__construct();
}
public function test() {
$lang = 6;
$code = 533001410;
$query = $this->db->query("SELECT DISTINCT
IF (ART_LOOKUP.ARL_KIND IN (3, 4), BRANDS.BRA_BRAND,
SUPPLIERS.SUP_BRAND) AS
BRAND, ART_LOOKUP.ARL_SEARCH_NUMBER AS NUMBER, ART_LOOKUP.ARL_KIND,
ART_LOOKUP.ARL_ART_ID, DES_TEXTS.TEX_TEXT AS ART_COMPLETE_DES_TEXT
FROM ART_LOOKUP
LEFT JOIN BRANDS ON BRANDS.BRA_ID = ART_LOOKUP.ARL_BRA_ID
INNER JOIN ARTICLES ON ARTICLES.ART_ID = ART_LOOKUP.ARL_ART_ID
INNER JOIN SUPPLIERS ON SUPPLIERS.SUP_ID = ARTICLES.ART_SUP_ID
INNER JOIN DESIGNATIONS ON DESIGNATIONS.DES_ID =
ARTICLES.ART_COMPLETE_DES_ID
INNER JOIN DES_TEXTS ON DES_TEXTS.TEX_ID = DESIGNATIONS.DES_TEX_ID
WHERE ART_LOOKUP.ARL_SEARCH_NUMBER = '.$code.' AND
ART_LOOKUP.ARL_KIND
IN (1, 2, 3, 4) AND DESIGNATIONS.DES_LNG_ID = '.$lang.'
GROUP BY BRAND, NUMBER");
return $query->result();
}
}
?>
Error Number: 1055
Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'dpazine.ART_LOOKUP.ARL_KIND' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_bySELECT DISTINCT IF (ART_LOOKUP.ARL_KIND IN (3, 4), BRANDS.BRA_BRAND, SUPPLIERS.SUP_BRAND) AS BRAND, ART_LOOKUP.ARL_SEARCH_NUMBER AS NUMBER, ART_LOOKUP.ARL_KIND, ART_LOOKUP.ARL_ART_ID, DES_TEXTS.TEX_TEXT AS ART_COMPLETE_DES_TEXT FROM ART_LOOKUP LEFT JOIN BRANDS ON BRANDS.BRA_ID = ART_LOOKUP.ARL_BRA_ID INNER JOIN ARTICLES ON ARTICLES.ART_ID = ART_LOOKUP.ARL_ART_ID INNER JOIN SUPPLIERS ON SUPPLIERS.SUP_ID = ARTICLES.ART_SUP_ID INNER JOIN DESIGNATIONS ON DESIGNATIONS.DES_ID = ARTICLES.ART_COMPLETE_DES_ID INNER JOIN DES_TEXTS ON DES_TEXTS.TEX_ID = DESIGNATIONS.DES_TEX_ID WHERE ART_LOOKUP.ARL_SEARCH_NUMBER = '.533001410.' AND ART_LOOKUP.ARL_KIND IN (1, 2, 3, 4) AND DESIGNATIONS.DES_LNG_ID = '.6.' GROUP BY
BRAND, NUMBERFilename: C:/wamp64/www/CodeIgniter/system/database/DB_driver.php
Line Number: 691
最佳答案
您的 GROUP BY 子句不包含 SELECT 中的所有非聚合字段,例如 ART_LOOKUP.ARL_KIND、ART_LOOKUP.ARL_ART_ID、DES_TEXTS.TEX_TEXT AS ART_COMPLETE_DES_TEXT。
请参阅此链接了解更多信息...
https://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html
也许可以将这些字段添加到您的 GROUP BY 中?
关于php - Codeigniter 请求 sql 但我的代码返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45872095/