phpwhere-clausewhere-inmysql-error-1054

How to fix Error Number: 1054 Unknown column 'Array' in 'where clause'


this is my error :

A PHP Error was encountered Severity: Notice Message: Array to string conversion Filename: templates/sidebar.php Line Number: 24 Backtrace:

File: A:\Sites\PHP_CI\hasan-login\application\views\templates\sidebar.php Line: 24 Function: _error_handler

File: A:\Sites\PHP_CI\hasan-login\application\controllers\Admin.php Line: 14 Function: view

File: A:\Sites\PHP_CI\hasan-login\index.php Line: 315 Function: require_once A Database Error Occurred

Error Number: 1054 Unknown column 'Array' in 'where clause'

SELECT user_menu.id, menu FROM user_menu JOIN user_access_menu ON user_menu.id = user_access_menu.menu_id WHERE user_access_menu.role_id = Array ORDER BY user_access_menu.menu_id ASC

Filename: A:/Sites/PHP_CI/hasan-login/system/database/DB_driver.php Line Number: 691

I use php codeigniter. but when I delete the part where the program runs smoothly. maybe an error in the where. how to fix this error?

this is my code :

<?php
//error_reporting(0);
$role_id = $this->session->userdata('role_id');
$queryMenu = "SELECT `user_menu`.`id`, `menu`
                FROM `user_menu` JOIN `user_access_menu`
                 ON `user_menu`.`id` = `user_access_menu`.`menu_id`
            WHERE `user_access_menu`.`role_id` = $role_id
            ORDER BY `user_access_menu`.`menu_id` ASC 
            ";
$menu = $this->db->query($queryMenu)->result_array();
var_dump($menu);
die;
?>

Solution

  • This is codeigniter, you can use the OOB functions given in codeigniter query builder page, by the way you should try this one:

     <?php
    $role_id = $this->session->userdata('role_id');
    $queryMenu = "SELECT `user_menu`.`id`, `menu`
                    FROM `user_menu` JOIN `user_access_menu`
                     ON `user_menu`.`id` = `user_access_menu`.`menu_id`
                WHERE `user_access_menu`.`role_id` = ?
                ORDER BY `user_access_menu`.`menu_id` ASC 
                ";
    $menu = $this->db->query($queryMenu,array($role_id))->result_array();
    var_dump($menu);
    die;
    ?>