Populate dropdown from external tables

In order to populate a selectbox field with values taken from an external table, you'll have to paste this script in the Scripts called on form Display, and change col1, col2 and my_external_table to match your needs.


foreach($fields as $i=>$field){
        $database->setQuery("SELECT col1 as val, col 2 as txt FROM my_external_table");
        $values = $database->loadObjectList();
        $default_value = array();
        foreach($values as $row){
            $default_value[]= $row->val.'|'.$row->txt;
        $default_value = implode(',',$default_value);
        $fields[$i]->default_value = $default_value;

4 persons found this article helpful.

Was this article helpful?

Yes No
Sorry about that