Hello! I have the following tables:
tbl_encargotbl_category
tbl_encargo
Since in tbl_lacamento
there is a field ( id_categoria
) that receives the ids of tbl_categoria
and tbl_categoria
receives its id ( id_juros
), coming from the tbl_juros
table.
I am using codeigniter and I want to display in a field hidden
<input type="hidden" id="juros" name="txt_juros" placeholder="juros" title="juros"/>
in view lançamento
all categories of tbl_categoria
, and I want to dynamically display all ids_juros
related to tbl_categoria
.
What I have today, displays only categories. Below a view
<select id="categoria" class="form-control" name="sel_id_categoria" >
<?php foreach ($categoria as $categoria) {
echo '<option value="'.$categoria->id.'">'.$categoria->descricao.'</option>';
} ?>
</select>
Controller code launching
//Listar Categorias ativas Receitas e Despesas
$this->load->model('app/Categoria_model');
$this->data['categoria'] = $this->Categoria_model->obter_ativo('tbl_categoria', 'tbl_categoria.id,tbl_categoria.descricao');
Code no model Category_model
//Listar ativos
var $tabela = 'tbl_categoria';
function obter_ativo($tabela,$campos)
{
$this->db->select($campos);
$this->db->from($tabela);
$this->db->where('situacao',1);
$query = $this->db->get();
return $query->result();;
}
-- -----------------------------------------------------
-- Table 'tbl_lancamento'
-- -----------------------------------------------------
DROP TABLE IF EXISTS 'tbl_lancamento';
CREATE TABLE IF NOT EXISTS 'tbl_lancamento'(
'id' INT(11) NOT NULL AUTO_INCREMENT,
'tipo' TINYINT(1) NOT NULL DEFAULT 0,
'dt_lancamento' DATETIME NULL DEFAULT NULL,
'descricao' VARCHAR(255) NULL DEFAULT NULL,
'valor' decimal(10,2) NOT NULL,
'dt_vencimento' DATE NOT NULL,
'id_categoria' INT(11) NULL DEFAULT NULL,
'id_juros' INT(11) NULL DEFAULT NULL,
'id_conta' INT(11) NULL DEFAULT NULL,
'baixado' TINYINT(1) NOT NULL DEFAULT 0,
'valor_pagamento' decimal(10,2) NOT NULL,
'dt_pagamento' DATE NULL DEFAULT NULL,
'forma_pagamento' VARCHAR(100) NULL DEFAULT NULL,
'estornado' TINYINT(1) NOT NULL DEFAULT 0,
'observacao' TEXT(160) NULL DEFAULT NULL,
PRIMARY KEY ('id'),
INDEX 'fk_tbl_lancamento_tbl_conta' ('id_conta' ASC),
CONSTRAINT 'fk_tbl_lancamento_tbl_conta'
FOREIGN KEY ('id_conta')
REFERENCES 'tbl_conta' ('id')
ON DELETE NO ACTION
ON UPDATE NO ACTION
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS 'tbl_categoria';
CREATE TABLE IF NOT EXISTS 'tbl_categoria' (
'id' int(11) unsigned NOT NULL AUTO_INCREMENT,
'descricao' varchar(45) NOT NULL,
'tipo' TINYINT(1) NOT NULL,
'id_juros' TINYINT(1) NOT NULL,
'aplicar_juros' TINYINT(1) NOT NULL,
'situacao' TINYINT(1) NOT NULL,
PRIMARY KEY ('id')
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS 'tbl_encargo';
CREATE TABLE IF NOT EXISTS 'tbl_encargo' (
'id' int(11) unsigned NOT NULL AUTO_INCREMENT,
'descricao' varchar(45) NOT NULL,
'juros' decimal(10,2) NOT NULL,
'multa' decimal(10,2) NOT NULL,
'funcao' varchar(250) NULL DEFAULT NULL,
'situacao' TINYINT(1) NOT NULL,
PRIMARY KEY ('id')
) ENGINE=InnoDB DEFAULT CHARSET=utf8;