Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gabisa select concat #18

Open
dens4t opened this issue Dec 14, 2021 · 3 comments
Open

Gabisa select concat #18

dens4t opened this issue Dec 14, 2021 · 3 comments

Comments

@dens4t
Copy link

dens4t commented Dec 14, 2021

Kodingan saya untuk select concat yaitu

return DataTables::use('tb_kelas')
        ->select("id, CONCAT(tingkat, abjad) as kelas")
        ->addColumn('action', function($data) {
            return "<a href=\"" . base_url('Kelas/'. $data->id . "/ubah")."\" class=\"btn btn-sm btn-success mr-1\"><i class=\"fas fa-edit\"></i> Ubah</a>
            <a href=\"#\" onclick=\"konfirmasiHapus(" . $data->id .")\" class=\"btn btn-sm btn-danger\"><i class=\"fas fa-trash\"></i> Hapus</a>";
        })->rawColumns(['action'])
        ->make(true);

dan untuk isian columns datatable di halaman frontendnya yaitu id dan kelas

error yang didapatkan

{
    "title": "mysqli_sql_exception",
    "type": "mysqli_sql_exception",
    "code": 500,
    "message": "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 5",
    "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Database\\MySQLi\\Connection.php",
    "line": 292,
    "trace": [
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Database\\MySQLi\\Connection.php",
            "line": 292,
            "function": "query",
            "class": "mysqli",
            "type": "->",
            "args": [
                "SELECT COUNT(*) AS `numrows`\nFROM `tb_kelas`\nWHERE   (\nabjad) LIKE '%%' ESCAPE '!'\n )",
                0
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Database\\BaseConnection.php",
            "line": 670,
            "function": "execute",
            "class": "CodeIgniter\\Database\\MySQLi\\Connection",
            "type": "->",
            "args": [
                "SELECT COUNT(*) AS `numrows`\nFROM `tb_kelas`\nWHERE   (\nabjad) LIKE '%%' ESCAPE '!'\n )"
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Database\\BaseConnection.php",
            "line": 598,
            "function": "simpleQuery",
            "class": "CodeIgniter\\Database\\BaseConnection",
            "type": "->",
            "args": [
                "SELECT COUNT(*) AS `numrows`\nFROM `tb_kelas`\nWHERE   (\nabjad) LIKE '%%' ESCAPE '!'\n )"
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Database\\BaseBuilder.php",
            "line": 1527,
            "function": "query",
            "class": "CodeIgniter\\Database\\BaseConnection",
            "type": "->",
            "args": [
                "SELECT COUNT(*) AS `numrows`\nFROM `tb_kelas`\nWHERE   (\nabjad) LIKE :abjad): ESCAPE '!'\n )",
                {
                    "abjad)": [
                        "%%",
                        true
                    ]
                },
                false
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\irsyadulibad\\codeigniter4-datatables\\src\\TableProcessor.php",
            "line": 35,
            "function": "countAllResults",
            "class": "CodeIgniter\\Database\\BaseBuilder",
            "type": "->",
            "args": [
                false
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\irsyadulibad\\codeigniter4-datatables\\src\\DataTableMethods.php",
            "line": 101,
            "function": "count",
            "class": "Irsyadulibad\\DataTables\\TableProcessor",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\irsyadulibad\\codeigniter4-datatables\\src\\TableProcessor.php",
            "line": 42,
            "function": "filterRecords",
            "class": "Irsyadulibad\\DataTables\\DataTableMethods",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\irsyadulibad\\codeigniter4-datatables\\src\\TableProcessor.php",
            "line": 27,
            "function": "doQuery",
            "class": "Irsyadulibad\\DataTables\\TableProcessor",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\Project\\Sekolah\\app\\Controllers\\KelasController.php",
            "line": 32,
            "function": "make",
            "class": "Irsyadulibad\\DataTables\\TableProcessor",
            "type": "->",
            "args": [
                true
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\CodeIgniter.php",
            "line": 824,
            "function": "ajaxList",
            "class": "App\\Controllers\\KelasController",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\CodeIgniter.php",
            "line": 410,
            "function": "runController",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->",
            "args": [
                {
                    "kelas": {
                        "pager": null
                    },
                    "validation": {}
                }
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\CodeIgniter.php",
            "line": 318,
            "function": "handleRequest",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->",
            "args": [
                null,
                {
                    "handler": "file",
                    "backupHandler": "dummy",
                    "storePath": "D:\\Project\\Sekolah\\writable\\cache/",
                    "cacheQueryString": false,
                    "prefix": "",
                    "ttl": 60,
                    "reservedCharacters": "{}()/\\@:",
                    "file": {
                        "storePath": "D:\\Project\\Sekolah\\writable\\cache/",
                        "mode": 416
                    },
                    "memcached": {
                        "host": "127.0.0.1",
                        "port": 11211,
                        "weight": 1,
                        "raw": false
                    },
                    "redis": {
                        "host": "127.0.0.1",
                        "password": null,
                        "port": 6379,
                        "timeout": 0,
                        "database": 0
                    },
                    "validHandlers": {
                        "dummy": "CodeIgniter\\Cache\\Handlers\\DummyHandler",
                        "file": "CodeIgniter\\Cache\\Handlers\\FileHandler",
                        "memcached": "CodeIgniter\\Cache\\Handlers\\MemcachedHandler",
                        "predis": "CodeIgniter\\Cache\\Handlers\\PredisHandler",
                        "redis": "CodeIgniter\\Cache\\Handlers\\RedisHandler",
                        "wincache": "CodeIgniter\\Cache\\Handlers\\WincacheHandler"
                    }
                },
                false
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\public\\index.php",
            "line": 37,
            "function": "run",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Commands\\Server\\rewrite.php",
            "line": 43,
            "args": [
                "D:\\Project\\Sekolah\\public\\index.php"
            ],
            "function": "require_once"
        }
    ]
}

Mohon untuk solusinya

@dens4t
Copy link
Author

dens4t commented Dec 16, 2021

halo ada solusinya ga?

@mdestafadilah
Copy link

halo ada solusinya ga?

coba pake reguler query mysql biasa.

"message": "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 5",

@meigiyanto
Copy link

Kodingan saya untuk select concat yaitu

return DataTables::use('tb_kelas')
        ->select("id, CONCAT(tingkat, abjad) as kelas")
        ->addColumn('action', function($data) {
            return "<a href=\"" . base_url('Kelas/'. $data->id . "/ubah")."\" class=\"btn btn-sm btn-success mr-1\"><i class=\"fas fa-edit\"></i> Ubah</a>
            <a href=\"#\" onclick=\"konfirmasiHapus(" . $data->id .")\" class=\"btn btn-sm btn-danger\"><i class=\"fas fa-trash\"></i> Hapus</a>";
        })->rawColumns(['action'])
        ->make(true);

dan untuk isian columns datatable di halaman frontendnya yaitu id dan kelas

error yang didapatkan

{
    "title": "mysqli_sql_exception",
    "type": "mysqli_sql_exception",
    "code": 500,
    "message": "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 5",
    "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Database\\MySQLi\\Connection.php",
    "line": 292,
    "trace": [
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Database\\MySQLi\\Connection.php",
            "line": 292,
            "function": "query",
            "class": "mysqli",
            "type": "->",
            "args": [
                "SELECT COUNT(*) AS `numrows`\nFROM `tb_kelas`\nWHERE   (\nabjad) LIKE '%%' ESCAPE '!'\n )",
                0
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Database\\BaseConnection.php",
            "line": 670,
            "function": "execute",
            "class": "CodeIgniter\\Database\\MySQLi\\Connection",
            "type": "->",
            "args": [
                "SELECT COUNT(*) AS `numrows`\nFROM `tb_kelas`\nWHERE   (\nabjad) LIKE '%%' ESCAPE '!'\n )"
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Database\\BaseConnection.php",
            "line": 598,
            "function": "simpleQuery",
            "class": "CodeIgniter\\Database\\BaseConnection",
            "type": "->",
            "args": [
                "SELECT COUNT(*) AS `numrows`\nFROM `tb_kelas`\nWHERE   (\nabjad) LIKE '%%' ESCAPE '!'\n )"
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Database\\BaseBuilder.php",
            "line": 1527,
            "function": "query",
            "class": "CodeIgniter\\Database\\BaseConnection",
            "type": "->",
            "args": [
                "SELECT COUNT(*) AS `numrows`\nFROM `tb_kelas`\nWHERE   (\nabjad) LIKE :abjad): ESCAPE '!'\n )",
                {
                    "abjad)": [
                        "%%",
                        true
                    ]
                },
                false
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\irsyadulibad\\codeigniter4-datatables\\src\\TableProcessor.php",
            "line": 35,
            "function": "countAllResults",
            "class": "CodeIgniter\\Database\\BaseBuilder",
            "type": "->",
            "args": [
                false
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\irsyadulibad\\codeigniter4-datatables\\src\\DataTableMethods.php",
            "line": 101,
            "function": "count",
            "class": "Irsyadulibad\\DataTables\\TableProcessor",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\irsyadulibad\\codeigniter4-datatables\\src\\TableProcessor.php",
            "line": 42,
            "function": "filterRecords",
            "class": "Irsyadulibad\\DataTables\\DataTableMethods",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\irsyadulibad\\codeigniter4-datatables\\src\\TableProcessor.php",
            "line": 27,
            "function": "doQuery",
            "class": "Irsyadulibad\\DataTables\\TableProcessor",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\Project\\Sekolah\\app\\Controllers\\KelasController.php",
            "line": 32,
            "function": "make",
            "class": "Irsyadulibad\\DataTables\\TableProcessor",
            "type": "->",
            "args": [
                true
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\CodeIgniter.php",
            "line": 824,
            "function": "ajaxList",
            "class": "App\\Controllers\\KelasController",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\CodeIgniter.php",
            "line": 410,
            "function": "runController",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->",
            "args": [
                {
                    "kelas": {
                        "pager": null
                    },
                    "validation": {}
                }
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\CodeIgniter.php",
            "line": 318,
            "function": "handleRequest",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->",
            "args": [
                null,
                {
                    "handler": "file",
                    "backupHandler": "dummy",
                    "storePath": "D:\\Project\\Sekolah\\writable\\cache/",
                    "cacheQueryString": false,
                    "prefix": "",
                    "ttl": 60,
                    "reservedCharacters": "{}()/\\@:",
                    "file": {
                        "storePath": "D:\\Project\\Sekolah\\writable\\cache/",
                        "mode": 416
                    },
                    "memcached": {
                        "host": "127.0.0.1",
                        "port": 11211,
                        "weight": 1,
                        "raw": false
                    },
                    "redis": {
                        "host": "127.0.0.1",
                        "password": null,
                        "port": 6379,
                        "timeout": 0,
                        "database": 0
                    },
                    "validHandlers": {
                        "dummy": "CodeIgniter\\Cache\\Handlers\\DummyHandler",
                        "file": "CodeIgniter\\Cache\\Handlers\\FileHandler",
                        "memcached": "CodeIgniter\\Cache\\Handlers\\MemcachedHandler",
                        "predis": "CodeIgniter\\Cache\\Handlers\\PredisHandler",
                        "redis": "CodeIgniter\\Cache\\Handlers\\RedisHandler",
                        "wincache": "CodeIgniter\\Cache\\Handlers\\WincacheHandler"
                    }
                },
                false
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\public\\index.php",
            "line": 37,
            "function": "run",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Commands\\Server\\rewrite.php",
            "line": 43,
            "args": [
                "D:\\Project\\Sekolah\\public\\index.php"
            ],
            "function": "require_once"
        }
    ]
}

Mohon untuk solusinya

Halo gan, coba cek solusi di #30 (comment) dan di commit ya?. Semoga membantu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants