datadoit
|
| Posted: 12/01/2008, 5:34 AM |
|
CCS 3.2; PHP5; MySQL5
Listbox values can be dynamically set via:
$Component->Values = array(array("1","one"), array("2","two"));
Easy enough. However, I need those values to come from the database.
Basically I need everything the wizard provides, but I need some
granular control over the values based on conditions. So here's where
I'm at:
<code>
$db = new DBConnection();
$sql = "SELECT extension FROM tbl_extensions WHERE whatever";
$db->query($sql);
while ($db->next_record()) {
**** Here's where those array values are populated. ****
}
$db->close();
</code>
How do I populate those array values to the listbox?
Thanks.
|
|
|
 |
feha
Posts: 712
|
| Posted: 12/01/2008, 7:06 AM |
|
Below is if you have already an array 
$my_box=array();
if (is_array($my_array))
{
foreach ($my_array as $key => $option)
{
$my_box []= array($key, $option);
}
}
// Listbox name of your component ...
$Component->Listbox->Value= $my_box;
in your case :
$my_box=array();
$db = new DBConnection();
$sql = "SELECT * FROM tbl_extensions WHERE whatever";
$db->query($sql);
while ($db->next_record()) {
$my_box []= array( $db->f("key"), $db->f("option") );
}
$db->close();
// populate your listbox ...
$Component->Listbox->Value= $my_box;
Always your's
feha
_________________
Regards
feha
www.vision.to
feedpixel.com |
 |
 |
datadoit
|
| Posted: 12/01/2008, 9:16 AM |
|
Of course, as usual, Feha is the guru!
Thanks!
|
|
|
 |
|