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

  • SEARCH
  • Home
  • 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 8299791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:17:31+00:00 2026-06-08T16:17:31+00:00

I want to get two field values from a database table and combine them

  • 0

I want to get two field values from a database table and combine them together and use that as the display text in the label. Also I want to make another field value in the table as the label id.

The AgeCat table stores the different age categories. The table definition is

age_cat_id ---> primary key
range_start
range_end

e.g:

age_cat_id=>1
range_start=>18
range_end=>24

What I want is to have the label text set as ‘”range_start” to “range_end”‘
e.g: ’18 to 24’

and the label id to be the age_cat_id.

What is the proper way to format the label text to display as above? I have retrieved all the records of the AgeCat table, and stored them in a string array ($agecats) using find(all). I’m having trouble retrieving values from that array and then format it according to above way and set as the label text. Please suggest if there is a better way to do this.

The purpose of this is to display each record in the AgeCat table following the format of ‘range_start to range_end’ but having their value set as the corresponding age_cat_id.
E.g: 18 to 24 is displayed using some form element but the value should be 1. It’s like having a drop down list with custom strings, but each linked to a unique value. So once an option is selected, the value is passed, not the string.

If the label is not good enough, what form element is suitable for this?

  • 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-08T16:17:32+00:00Added an answer on June 8, 2026 at 4:17 pm

    Virtual fields:cakephp documentation.

    public $virtualFields = array(
    'cat_date' => 'CONCAT(AgeCat.range_start, " to ", AgeCat.range_end)'
    );
    

    P.S.: according to Cakephp conventions the primary key should be named id.

    Edit: take a look there: form helper

    echo $this->Form->select('id', $cat_date)
    

    In the controller something like this:

    $cat_date=$this->Model->find('list',array('fields'=>array('id','cat_name')));
    

    with $cat_date an array containing the desired values in the select.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to concatenate two form text field values and assign them to my
I have two employee lists that I want to get only unique records from
Using Access 2003 I want to get a table value from the two databases
I want to get data from two tables. I have patient first name and
I want to get data from two tables with single Entity class. How?? public
I want to get the single digits from two digits.for example if 36 I
If I want to get to a value in vector I can use two
I want an adaptable database scheme. But still use a simple table data gateway
Here am trying to get values from a mysql table with the name lead.
I want to define a custom exception that has two special properties: Field and

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.