Cleopatra
Posts: 73
|
| Posted: 06/16/2010, 11:33 AM |
|
Hey guys,
Is it possible to filter the values displayed by a (multi) listbox for example with custom sql and where conditions?
If so, can anyone explain to me how and in which event I should place the code.
really stuck with this one, so all help is appreciated.
Thanks in advance
Cleo
_________________
php newbie |
 |
 |
raphaelbiz
Posts: 10
|
| Posted: 06/17/2010, 4:53 AM |
|
Dude,
I do all from constructor and i have sucess,
study the documentation, can be easy.
_________________
linuxell.serveftp.com |
 |
 |
Cleopatra
Posts: 73
|
| Posted: 06/17/2010, 7:20 AM |
|
Dude, I'm not a dude.
If I was I'd be a hot one, haha 
The reason I asked for help is cuz I'm running out of time.
_________________
php newbie |
 |
 |
magus
Posts: 98
|
| Posted: 06/18/2010, 9:21 PM |
|
Hello Cleo,
I use the functions below to dynamically set multi-select values.
I use use the AfterExecuteSelect event for your record but you can probably use one of the component events to run the code.
To load selected values.
$db = YOUR DATABASE CONNECTION;
$sql = "YOUR SQL"; // return 1 column.
$Component->[REPLACE WITH component_name]->SetValue(GetSelectedList($db,$sql));
To Load Available Options;
$db = YOUR DATABASE CONNECTION;
$sql = "YOUR SQL"; // return 2 columns
$Component->[REPLACE WITH component_name]->SetValues(GetListValues($db,$sql));
Regards,
Don A
//GetSelectedList
function GetSelectedList(&$db, $sql, $where = "", $order_by = "", $bound_column = "")
{
$values = "";
if(!strlen($bound_column))
$bound_column = 0;
if(strlen($where))
$sql .= " WHERE " . $where;
if(strlen($order_by))
$sql .= " ORDER BY " . $order_by;
$db->query($sql);
if ($db->next_record())
{
do
{
$values[] = $db->f($bound_column);
} while ($db->next_record());
}
return $values;
}
//End GetSelectedList
function GetListValues(&$db, $sql, $where = "", $order_by = "", $bound_column = "", $text_column = "")
{
$errors = new clsErrors();
$values = "";
if(!strlen($bound_column))
$bound_column = 0;
if(!strlen($text_column))
$text_column = 1;
$db->query(CCBuildSQL($sql, $where, $order_by));
if ($db->next_record())
{
do
{
$bound_column_value = $db->f($bound_column);
if($bound_column_value === false) {$bound_column_value = "";}
$values[] = array( $db->f($bound_column), $db->f($text_column));
} while ($db->next_record());
}
return $values;
}
|
 |
 |
Cleopatra
Posts: 73
|
| Posted: 06/20/2010, 10:00 AM |
|
Wow, thank you so much magus. You are so awesome!!!!!!
I will give this a try.
_________________
php newbie |
 |
 |
|