CodeIgniter Forums
Strange problem with dropdown - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Strange problem with dropdown (/showthread.php?tid=45703)



Strange problem with dropdown - El Forum - 10-02-2011

[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> &lt;?php echo anchor('detail/index/'.$row->id,$row->name); ?&gt; </strong> </p>
<p>  <img >image ?&gt;.jpg" width="20%" height="20%" border="1px"/> </p>
<p> Price: &lt;?php echo $row->price; ?&gt; Kč     </p>
  
  &lt;?php
  endforeach;
  endif; ?&gt;

<strong> Search </strong>

&lt;?php echo form_open('site/order'); ?&gt;
<p> &lt;?php echo form_dropdown('color',$colors,'white'); ?&gt; </p>
&lt;?php echo form_submit('submit','Search'); ?&gt;
&lt;?php echo form_close(); ?&gt;

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