简体   繁体   English

从result_array()中提取其类型的值

[英]extract values of their type from result_array()

I want to be able to take values from a result_array() query to use in another query. 我希望能够从result_array()查询中获取值以在另一个查询中使用。

Array ( 
  [0] => Array ( [taskID] => 10 )
  [1] => Array ( [taskID] => 11 )
  [2] => Array ( [taskID] => 12 )
)

I want to be able to loop through each of the items in the array and return the value (eg 10, 11, 12) to be used in a where clause. 我希望能够循环遍历数组中的每个项目并返回要在where子句中使用的值(例如10,11,12)。

$task being the array and $t being the items in the array. $task是数组, $t是数组中的项。

foreach($task as $t){
    $this->db->select('roleID');
    $this->db->from('project_tasks');
    $this->db->where('taskID', $t); //ERROR line 287
}

ERROR: 错误:

Error Number: 1054 错误号码:1054

Unknown column 'Array' in 'where clause' 'where子句'中的未知列'Array'

SELECT roleID FROM project_roles WHERE taskID = Array SELECT roleID FROM project_roles WHERE taskID = Array

Filename: models/Project_model.php 文件名:models / Project_model.php

Line Number: 287 行号:287

foreach($task as $t){
    $this->db->select('roleID');
    $this->db->from('project_tasks');
    $this->db->where('taskID', $t['taskID']);
}

You're forgetting that $task is an array of arrays: 你忘了$task是一个数组数组:

foreach($task as $t){
    $this->db->select('roleID');
    $this->db->from('project_tasks');
    $this->db->where('taskID', $t['taskID']); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM