|
Re: drop-down [message #2548 is a reply to message #2547] |
Wed, 16 June 2010 03:55 |
AJM
Messages: 2370 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
The ValRep array that is used to build a dropdown list or radio group is a simple associative array made up of value=representation pairs, where 'value' is the internal value used by the system, and 'representation' is a description which can be shown in the user's language of choice.
This means that the 'value' part can be used to look up a database record via its primary key. If this is a composite key, then the 'value' string must contain every part of this composite. You can do this by constructing a string in the format 'part1/part2/part3' where '/' is a separator which does not appear in any of the parts. Once the user has chosen a value you will then have to split out the parts before performing the database lookup.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
Re: drop-down [message #2550 is a reply to message #2549] |
Wed, 16 June 2010 08:52 |
AJM
Messages: 2370 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
Here is an example of how to build a ValRep array with composite keys:
$this->sql_select = 'part1, part2, description';
$this->sql_orderby = 'part1, part2';
$this->sql_ordery_seq = 'asc';
$data = $this->getData(null);
// convert each row into 'id=desc' in the output array
foreach ($data as $row => $rowdata) {
$key = $rowdata['part1].'/'.$rowdata['part2'];
$array[$key] = $rowdata['description'];
} // foreach
return $array;
Note here that each key string is in the format 'part1/part2' with '/' as the separator. When the selected key is sent in via the $_POST array you have to split this single string field back into its component parts.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|