I have added a filter field, so you can display only certain record, like the active ones or from a group only, so in your definition file (.yml) put something like this:
moneda:
class: DbDropDown
params:
field:valor
table:catalogo
primary_key:cod
filter: where grupo='MONEDA'
pais:
class: DbDropDown
params:
field:valor
table:catalogo
primary_key:cod
filter: where grupo='PAIS'
So the source modified is like this:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
include_once("dropdown.php");
class DbDropDown extends DropDown{
var $primary_key = 'id';
var $table = '';
var $field = '';
var $filter = '';
function DbDropDown($name,$params){
DropDown::DropDown($name,$params);
if(isset($this->params['primary_key']))
$this->primary_key = $this->params['primary_key'];
if(isset($this->params['filter']))
$this->filter = $this->params['filter'];
if(isset($this->params['table']))
$this->table = $this->params['table'];
else
show_error($this->lang->line('codexforms_dbdropdown_table_not_defined'));
if(isset($this->params['field']))
$this->field = $this->params['field'];
else
show_error($this->lang->line('codexforms_dbdropdown_field_not_defined'));
}
function prepForDisplay($value){
if(empty($value))
return '';
$CI = &get_instance();
$CI->db->select($this->field);
$CI->db->where($this->primary_key,$value);
$query = $CI->db->get($this->table);
$result = $query->result_array();
if(count($result) == 0)
return '';
else
return $result[0][$this->field];
}
function getList(){
$CI = &get_instance();
if(!isset($CI->db)) $CI->load->database();
$html = "<option value =""></option>";
$field = $this->params['field'];
$table = $this->params['table'];
$result = $CI->db->query("SELECT ".$this->primary_key.",$field FROM $table ".$this->filter);
foreach($result->result_array() as $row){
if($row[$this->primary_key] == $this->value)
$html .= "<option value="".$row[$this->primary_key]."" selected>".$row[$field]."</option>n";
else
$html .= "<option value="".$row[$this->primary_key]."">".$row[$field]."</option>n";
}
return $html;
}
}
?>
Comments (0)
You don't have permission to comment on this page.