I have a piece of code in cake where I am getting multiple rows of data back from SQL, and in one of the columns there is a numeric value I need to check and change the data to text if it equals a certain number. In order to do this I need to know how the array elements are named $results[????] in order to get this value and change it. So what are the naming conventions of arrays when using SQL/Cake?
Here is the caked code:
$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);
And I am getting the data here:
foreach ($rs as $record){
try {
$result[] = $record[$this->name];
array_push($result, $record['DD']);
}
}
And returning it to be printed out as a JSON object. So I want to get into $results[] to check the numeric value of SOURCE_ID and ROUTE_ID. How can I do this without doing a foreach?
I figured it out:
When using caking SQL statements, the a 3-D array is given back (2-D when only one field, or select, is requested). They are named as such:
And when each is run through a foreach statement, the element changes to a number
[table_name]or[column_name]is now[0], or[1], etc. depending on where it is in the array.In order to check the numeric values of
ROUTE_IDandSOURCE_IDI created a hash table as suchand ran through the values of each row of
SOURCE_IDandROUTE_IDas such: