mysql - 通过传递数组从数据库中检索记录

标签 mysql codeigniter

我的 Controller 代码

public function all_ratings(){
  $result_ratings = $data['result_ratings'] ; 
  **(I have successfully captured '$result_ratings' data here)**

  $first_names = array_column($result_ratings, 'customer_id');
  $data['result_cus'] =$this->mod_customers->get_unique_customer($first_names);

  //var_dump($data['result_cus']); die(); 
  data['related_view']='system_rating_appointments';
  $this->load->view('template', $data);
}

我的模型代码(mod_customers)

public function get_unique_customer($first_names){
    $this->load->database();     
    $this->db->where('id', $first_names);    
    $query = $this->db->get($this->table);
    return $query->result_array();
  }

结果

发生数据库错误

错误号:1054

“where 子句”中的未知列“数组”

tbl_customer中选择*,其中id = 数组

文件名:C:/wamp64/www/theme/system/database/DB_driver.php

行号:691

大家好,我是 codeignitor 的新手。我想从上表中检索数组的每个值的记录。但是发生了错误。请帮助我。

注意:数据库、表定义在模型页面顶部

最佳答案

尝试使用 where_in 方法,因为您为条件提供 $first_names 数组:

$this->db->where_in('id', $first_names);

关于mysql - 通过传递数组从数据库中检索记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49340904/

相关文章:

php - 无法使用 php 获取和显示数据

mysql - 我无法将股票数据插入我的数据库

php - 获取 $_SESSION 中的时间戳 mysql 值

mysql - 任何人都可以向我解释这个查询的作用吗?

模型中的 Codeigniter 和 Set Session

php - URL 中的加密数据

mysql - 如何在 MySQL 中编写用户定义的函数,以便当我从一个表中删除一行时,另一个表中的特定行也会被删除?

jquery - Plupload 和错误生成

php - Codeigniter 使用表单为表的每一行传递 id

javascript - 如何更改特定按钮,而不使用 jquery 中的 `this` 命令