select option as paramenter for method codeigniter

0

I have a problem that I can not solve at all. I have a form html which has a select option I need to pick the selected value when the form is sent and use as a parameter for a method, is there any way to do that?

    
asked by anonymous 21.12.2015 / 01:38

1 answer

2

There is, my friend. Assuming the name of the combobox is consulta would look like this in the controller:

public funcition Consultar(){
$parametro = $this->input->post('consulta'); //formulário submetido via POST

/*lembrando que o valor que virá submetido pelo formulário 
é o que se encontra em value lá no html */

$this->load->model('Nome_da_tua_model');
$res = $this->Nome_da_tua_model->Teu_metodo_de_consulta($parametro);
}

In your model would look like this:

public function Teu_metodo_de_consulta($parametro){
$this->db->Select('*');
$this->db->From('Tua_tabela');
if(!empty($parametro)){
$this->db->where('Tua_tabela.Teu_campo', $parametro);
}
$result = $this->db->get()->Result();
return $result;
} 

Now in the controller the variable $res has the data of your query.

The SQL command I executed in the above section is for equal values, if you need another type of comparison, I advise you to read the documentation at link .

I hope I have helped, Oss!

    
22.12.2015 / 18:41