0
votes

I am looking to display the result of an SQL request, but my code returns me an error that I have trouble resolving. I'll be thankful if someone can help me.

I'm working with 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_by

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 = '.533001410.' AND ART_LOOKUP.ARL_KIND IN (1, 2, 3, 4) AND DESIGNATIONS.DES_LNG_ID = '.6.' GROUP BY
BRAND, NUMBER

Filename: C:/wamp64/www/CodeIgniter/system/database/DB_driver.php
Line Number: 691

2
run your query in phpmyadmin first and check - umefarooq

2 Answers

0
votes

Your GROUP BY clause doesn't contain all your non-aggregrated fields in the SELECT, like ART_LOOKUP.ARL_KIND, ART_LOOKUP.ARL_ART_ID, DES_TEXTS.TEX_TEXT AS ART_COMPLETE_DES_TEXT.

See this link for more...

https://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html

Maybe add those fields to your GROUP BY?

0
votes

This isn't any problem with your query thats mysql configurations issue

Solution.

Open my.cnf Mysql Configurations file

and place this piece of code there hour problem will be solved

[mysqld]
sql_mode=''