如何在CodeIgniter中将数组值返回/转换为$ row

时间:2011-07-20 03:01:55

标签: arrays codeigniter model filter

我想将我的数组值转换为CodeIgniter中的$ row,结果是Array()

$info[] =array('name'=>$row['name']);
Example : Array ( [name] => AA01) and more...20 records

然后我将它们用于Model,在Model

中创建一个查询过滤器
$data['filter_list'] = $this->modeltype_model->getAssignedFilter($info);

我的模特

function getAssignedFilter($info)
{
    $sql = "SELECT name, type, color FROM cars "
            . "WHERE deleted=0 "
            . "AND name IN "
            . "(SELECT type FROM color_cars WHERE name_type='"
            . $info . "')"; // $info , must row value

    $query = $this->db->query($sql);

    return $query;      
}

CodeIgniter如何处理这个问题?有什么建议吗?

谢谢你 MRizq

1 个答案:

答案 0 :(得分:1)

尝试

$info[] = "'".$row['name']."'";
$filter= implode(",",$info);

然后

$data['filter_list'] = $this->modeltype_model->getAssignedFilter($filter);

模型

function getAssignedFilter($filter){
    $sql = "SELECT name, type, color FROM cars 
                WHERE deleted=0 
                AND name IN 
                (SELECT type FROM color_cars WHERE name_type IN ($filter))";
    $query = $this->db->query($sql);

    return $query;      
}