[eluser]Michal1[/eluser]
Hello guys I am having a really strange problem with dropdown and I cannot figure out what is wrong. I am trying to receive value from dropdown and then use it as parameter in my model function but it does not give me a value.
My site controller looks like
Code:
class Site extends Controller{
public function index()
{
$data = array();
$data['colors'] = array(
'red'=>'red',
'white'=>'white',
'blue'=>'blue',
);
if ($query = $this->site_model->get_data())
{
$data['cars']= $query;
}
$this->load->view('site_view',$data);
}
public function order()
{
$data = array();
$data['colors'] = array(
'red'=>'red',
'white'=>'white',
'blue'=>'blue',
);
if ($query = $this->site_model->get_order($this->input->post('color')))
{
$data['cars'] = $query;
}
$this->load->view('site_view',$data);
}
}
My view:
Code:
<?php if (isset($cars)): foreach ($cars as $row) : ?>
<p> <strong> <?php echo anchor('detail/index/'.$row->id,$row->name); ?> </strong> </p>
<p> <img >image ?>.jpg" width="20%" height="20%" border="1px"/> </p>
<p> Price: <?php echo $row->price; ?> Kč </p>
<?php
endforeach;
endif; ?>
<strong> Search </strong>
<?php echo form_open('site/order'); ?>
<p> <?php echo form_dropdown('color',$colors,'white'); ?> </p>
<?php echo form_submit('submit','Search'); ?>
<?php echo form_close(); ?>
and my model function
Code:
class Site_model extends Model{
public function get_data()
{
$this->db->order_by("id",'desc');
$query = $this->db->get('cars');
return $query->result();
}
public function get_order($first)
{
$this->db->where('color',$first);
$this->db->order_by("id","desc");
$query = $this->db->get('cars');
return $query->result();
}
}
the thing is that when I pick a color in dropdown and click submit i should get some result. Unfortunately it does not work. For example in my database one field has color "red" and when i pick red in dropdown i still dont receive nothing. Does somebody what is going on? Thank you