Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8270643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:38:33+00:00 2026-06-08T06:38:33+00:00

I have a piece of code in cake where I am getting multiple rows

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T06:38:36+00:00Added an answer on June 8, 2026 at 6:38 am

    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:

    Array(
        Array[table_name] =>
            [column_name] => field value
            [column_name] => field value
            .
            .
        Array[table_name] =>
            [column_name] => field value
            [column_name] => field value
            .
            .
        .
        .
    );
    

    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_ID and SOURCE_ID I created a hash table as such

    $sourceValues = array(
            500002 => 'Verbal',
            500003 => 'Telephone',
            500004 => 'Written',
            500005 => 'Other'
        );
    
    $routeValues = array(
            11     => 'Intramuscular',
            22     => 'Nasal',
            28     => 'Subcutaneous'
        );
    

    and ran through the values of each row of SOURCE_ID and ROUTE_ID as such:

    foreach($record as $value){
               $source = $value['SOURCE_ID'];
               $route = $value['ROUTE_ID'];
               $value['SOURCE_ID'] = $sourceValues[$source];
               $value['ROUTE_ID'] = $routeValues[$route];
               $result[] = $value;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of code in one of my .jade files: each item
I have a piece of code getting the roots of an integer. I would
I have a piece of code from an assignment I am uncertain about. I
I have a piece of code as follows. Select * from abc_table where objectsnames=obj1
I have a piece of code that sets up a capture session from the
Here I have piece of code, showing example of how I want to update
I have a piece of code like this: <div id=container runat=server> <div id=parent runat=server>
I have this piece of code in a function. I want to print the
I have a piece of code that was written by someone else before the
I have this piece of code: public static DateDialogFragment newInstance(Context context, DateDialogFragmentListener listener) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.