Dropdown list [message #4473] |
Mon, 18 August 2014 09:21 |
htManager
Messages: 442 Registered: May 2014
|
Senior Member |
|
|
I have a dropdown list in which I want to list entries from a database table. Now I don't know how to change or create the selection criteria.
Can I change the $where criteria in the _cm_getValRep method of the class? If yes, how can I do this?
The first fields of the primary key are the same for both tables. So how can I get these values for using in the selection criteria?
Here is the code:
function _cm_getValRep ($item=null, $where=null)
// get Value/Representation list as an associative array.
{
$array = array();
if ($item == 'ma_mitglieder') {
// get data from the database
$where = $where_mannschaft;
$this->sql_select = 'kontakt_ma_user_id, kontakt_ma_user_seq_no, kontakt_ma_name, kontakt_ma_vorname';
$this->sql_orderby = 'kontakt_ma_name';
$this->sql_ordery_seq = 'asc';
$data = $this->getData($where);
// convert each row into 'id=desc' in the output array
foreach ($data as $row => $rowdata) {
$rowvalues = array_values($rowdata);
$array[$rowvalues[0]] = $rowvalues[0];
} // foreach
return $array;
} // if
return $array;
} // _cm_getValRep
|
|
|
Re: Dropdown list [message #4474 is a reply to message #4473] |
Mon, 18 August 2014 11:55 |
AJM
Messages: 2373 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
If you look very carelfully at the getValRep() and _cm_getValRep() methods inside std.table.class.inc you will see that they both have optional arguments for $where and $orderby. Inside the _cm_getValRep() method you will see the following line of code:
$data = $this->getData($where);
This means that all you have to do is supply a value for $where when you call the getValRep() method.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
Re: Dropdown list [message #4483 is a reply to message #4482] |
Tue, 19 August 2014 06:31 |
AJM
Messages: 2373 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
You only need to provide a $where string if you want a subset of the records from the ValRep table. By default it will select all records. If you want a subset then it is up to you to provide the $where string manually. The framework cannot do that for you as it does not know what subset you want.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|