CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> Tips & Solutions

 Displaying 2 fields combined in a listbox ( concat ) PHP

Print topic Send  topic

Author Message
andy


Posts: 183
Posted: 07/25/2007, 7:45 AM

If you would like to display 2 fields with a separator or space between them in a listbox

such as:

Field1 :: Field2

Then this is how you do it:
In the Data properties for the listbox, select SQL under Data Source Type.
In Data Source, click on the ... to enter the query builder.
You will want to select 2 fields. One for the bound column (data stored at database level) and one for the Text column (data displayed on the form).
The Text column is a concatanation of 2 fields with a separator in the middle.
Here is an example:

SELECT Name, concat(AccountType," :: ",Name) 2cols       
FROM account       
WHERE AccountType="Cost of Goods Sold"      
ORDER BY ID  


Name and AccountType are fields in the table "account"
Name is selected and the alias (made up name) "2cols" is selected.
2 cols displays as AccountType :: Name
You can include a Where statement if you want to limit the records displayed.
You can include an ORDER BY field to change the sort order

Then - to continue this example - in the Data properties for the listbox,
select Name under Bound column
select 2cols under Text column

You can of course change the separator by putting a space or any other characters between double quotes in the sql statement

Ta da
_________________
Andy

RAD tools for rich UI controls:
http://www.koolphptools.com
View profile  Send private message
wkempees


Posts: 1679
Posted: 07/25/2007, 11:10 AM

And if you like to do the same on a Listbox that is already functioning:

Open the Listbox's Datasource [..]
click SELECT, look al lower right pane of VQB
where it says (using same example)
on one row Name
and on the next AccountType

Change AccountType to
concat(AccountType, " :: ", Name)
and in the next column (Alias) type AccountType

This will
a/ do the same as Andy's example
b/ allow for maximum result at minimum effort
c/ leave the DataSource type: Table and not change it to SQL

For MySQL users, you can also use
concat_ws(<separator>,<fieldname>[,<fieldname>])
which rewrites above example as concat_ws(" :: ", AccountType, Name)

Just thought I'd mention it.
I always start out with the simple version of a listbox and using above
described expand it.

Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
marcwolf


Posts: 361
Posted: 08/05/2007, 4:34 AM

Nice ideas.. and a couple of suggestions..

Use monospaced font for the list box... Like Courier

And with various DB servers to can do pads and trips so to limit each 'column'

I've used this before and it really looks good. Something akin to MSAccess Listboaxes and Combo's

Take Care

Dave
_________________
' Coding Coding Coding
Keep Those Keyboards Coding.
Raw Code!!!!!!!
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.