Php 使用数组从单独的数据库筛选数据库查询结果

Php 使用数组从单独的数据库筛选数据库查询结果,php,database,codeigniter,Php,Database,Codeigniter,我有很多网站都是从一个数据库中提取数据。所有这些几乎都是相同的,并建立在CodeIgniter之上 每个数据库都有一个单独的数据库,其中包含特定于该站点的数据 通用数据库: 表“课程”= 列:id、课程名称、价格、外部链接、跟踪链接 站点特定数据库: 表“课程”= 列:id、活动、描述 每个站点从Universal数据库中提取一个课程和课程数据池,但是每个站点可以确定哪些课程是“活动的”。我可以从特定于站点的数据库中获取“active”=1的行的所有ID,并将它们传递给数组 但是,我想使用该查询

我有很多网站都是从一个数据库中提取数据。所有这些几乎都是相同的,并建立在CodeIgniter之上

每个数据库都有一个单独的数据库,其中包含特定于该站点的数据

通用数据库: 表“课程”= 列:id、课程名称、价格、外部链接、跟踪链接

站点特定数据库: 表“课程”= 列:id、活动、描述

每个站点从Universal数据库中提取一个课程和课程数据池,但是每个站点可以确定哪些课程是“活动的”。我可以从特定于站点的数据库中获取“active”=1的行的所有ID,并将它们传递给数组

但是,我想使用该查询中的ID作为通用数据库上的过滤器,将课程数据拉入站点的各个部分

这是我的模型:

public function getActiveCourses() {

    $local_db = $this->load->database('local', TRUE);
    $universal_db = $this->load->database('universal', TRUE);       


    $activeCourses =    $local_db
                ->where('active', 1)
                ->select('id')
                ->get('courses');
    $activeList = $activeCourses->result_array();



    $allCourses =   $universal_db
            ->where('id', $activeList)
            ->get('courses');

    return $allCourses->result_array();

}
但是我得到了以下错误

 Error Number: 1054

 Unknown column 'Array' in 'where clause'

 SELECT * FROM (`courses`) WHERE `id` = Array

 Filename: /models/courses.php

 Line Number: 39
第39行是:

$allCourses =       $universal_db
            ->where('id', $activeList)
            ->get('courses');  <== Line 39

return $allCourses->result_array();
$allCourses=$universal\u db
->其中('id',$activeList)
->获取(“课程”);结果_数组();
我已经搜索和玩了好几个小时了。任何帮助都是非常感谢的

CI和php新手,如有必要,可以提供更多详细信息。不确定什么是最需要的


Trey

那么,$activeList是一个数组,但您需要提供一个值:

$activeList = $activeCourses->result_array(); // see, "result_array"
// here you're returning the row in array format (array ['id'] =>...)
$allCourses =   $universal_db
            ->where('id', $activeList)  // here are you using the whole array!
            ->get('courses');
应该是这样的:

$allCourses =   $universal_db
            ->where('id', $activeList['id']) // passing the specific array index
            ->get('courses');

在universal db上使用时,您可能正在查找
where_in()
?不能将数组传递给
where()