Concatenate two fields

5 posts by 2 authors in: Forums > CMS Builder
Last Post: September 14, 2011   (RSS)

I have a table where I want to concatenate two fields to display in a drop down list. The fields are "num" and "zone_name".

I assume I will probably have to do a "left-join", but need some help with the code.

Any help appreciated!

Ragi
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

Re: [northernpenguin] Concatenate two fields

By Dave - September 13, 2011

Hi Ragi,

You mean in the CMS right? I think I know what you mean. Here's an example:

- Create a list field
- Set "List Options" to "Get options from MySQL query (advanced)"
- Use a query like this:
SELECT num, CONCAT(num, ' - ', email)
FROM `<?php echo $TABLE_PREFIX ?>accounts`


The first column value returned by the query is the value used in the database, the second value is the "label" displayed to the user. This loads users from the 'accounts' table and displays them like this "1 - dave@interactivetools.com".

Just switch the fieldnames and tablenames and it should work for you.

Hope that helps! Let me know how it goes.
Dave Edis - Senior Developer
interactivetools.com

Re: [northernpenguin] Concatenate two fields

By Dave - September 14, 2011

Hi Ragi,

The simple fix is to add +0 so mysql coverts it to a number:
'orderBy' => ' sqn_num+0 ',

Or another solution is to edit the field under: Admin > Section Editors > Field Editor and set the MySQL Column Type at the very bottom.

Let me know if either of those work for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Concatenate two fields

Thanx Dave! Your first solution worked.

Ragi
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke