Php 使用cake/sql时的数组元素命名
我有一段代码,我从SQL中获取了多行数据,在其中一列中有一个数值,我需要检查并将数据更改为文本,如果它等于某个数字。为了做到这一点,我需要知道数组元素是如何命名的,Php 使用cake/sql时的数组元素命名,php,arrays,cakephp,Php,Arrays,Cakephp,我有一段代码,我从SQL中获取了多行数据,在其中一列中有一个数值,我需要检查并将数据更改为文本,如果它等于某个数字。为了做到这一点,我需要知道数组元素是如何命名的,$results[??],以便获取并更改该值。那么,在使用SQL/Cake时,数组的命名约定是什么呢 以下是结块代码: $params = array( 'fields' => array( $this->name . '.AUTHORIZE_PROVIDER_NAME',
$results[??]
,以便获取并更改该值。那么,在使用SQL/Cake时,数组的命名约定是什么呢
以下是结块代码:
$params = array(
'fields' => array(
$this->name . '.AUTHORIZE_PROVIDER_NAME',
$this->name . '.SOURCE_ID',
$this->name . '.ORDER_ITEM_TITLE',
$this->name . '.DOSE_AMOUNT',
$this->name . '.DOSE_UNIT',
$this->name . '.DT_CREATED_TIME',
$this->name . '.ROUTE_ID',
$this->name . '.SEQUENCE_NO',
$this->name . '.LOCATION',
$this->name . '.BODY_SITE_ID',
$this->name . '.COMMENT',
'DD.DICTIONARY_DATA_CODE',
),
/*
'conditions' => array(
//conditions
$this->name . '.HID' => $hospital_id,
$this->name . '.PID' => $patient_id,
),
*/
'order' => array(
$this->name . '.DT_CREATED_TIME',
),
'joins' => array(
array(
'table' => 'DICTIONARY_DATA',
'alias' => 'DD',
'type' => 'INNER',
'fields' => 'DD.DICTIONARY_DATA_CODE as DD_Code',
'conditions'=> array(
$this->name . '.PRIORITY_ID = DD.DICTIONARY_DATA_ID',
$this->name . '.HID' => $hospital_id,
$this->name . '.PID' => $patient_id,
)
)
),
);
$rs = $this->find('all', $params);
我在这里得到数据:
foreach ($rs as $record){
try {
$result[] = $record[$this->name];
array_push($result, $record['DD']);
}
}
并返回它作为JSON对象打印出来。所以我想进入$results[]
来检查源ID
和路由ID
的数值。如果不为每个人执行操作,我怎么能做到这一点呢?我想:
当使用结块SQL语句时,将返回三维数组(当仅请求一个字段或select时为二维)。它们的名称如下:
Array(
Array[table_name] =>
[column_name] => field value
[column_name] => field value
.
.
Array[table_name] =>
[column_name] => field value
[column_name] => field value
.
.
.
.
);
当通过foreach语句运行每个元素时,元素将变为数字[表名]
或[列名]
现在是[0]
或[1]
,等等,这取决于它在数组中的位置
为了检查ROUTE\u ID
和SOURCE\u ID
的数值,我创建了一个哈希表
$sourceValues = array(
500002 => 'Verbal',
500003 => 'Telephone',
500004 => 'Written',
500005 => 'Other'
);
$routeValues = array(
11 => 'Intramuscular',
22 => 'Nasal',
28 => 'Subcutaneous'
);
并遍历SOURCE\u ID
和ROUTE\u ID
每行的值,如下所示:
foreach($record as $value){
$source = $value['SOURCE_ID'];
$route = $value['ROUTE_ID'];
$value['SOURCE_ID'] = $sourceValues[$source];
$value['ROUTE_ID'] = $routeValues[$route];
$result[] = $value;
}