Welcome Guest, Not a member yet? Register   Sign In
multiple dropdown search with codeigniter
#1

[eluser]Unknown[/eluser]
Hi Everybody..

I'm new in codeigniter..

I want to create an search module with 3 dropdown box in 3 different coloumn database.

plz anybody give smart tutorial link, and guide me..
#2

[eluser]boltsabre[/eluser]
If they are drop downs, then it's really simple.

Just put your drop downs into your html form and pass the values to your model.

Once in your model, depending on your preferred method of building sql queries (using active records or hard coding it) you simply build your statement depending on if each drop down has a selected value, here is the pseudo code for the "WHERE" part of your statement using active records:
Code:
if(isset($dropdown1) $this->db->where('column_1_name', $dropdown1);
if(isset($dropdown2) $this->db->where('column_2_name', $dropdown2);
if(isset($dropdown3) $this->db->where('column_3_name', $dropdown2);

Or you can use an associative array as per the user_guide located here:
http://ellislab.com/codeigniter/user-gui...tml#select

If you are having problems with forms, controller, passing from values from the form to the model, or anything else, first I'd recommend to watch and code along with some of the many tutorials around.
http://codeigniter.com/tutorials/
#3

[eluser]Unknown[/eluser]
In my code using input textbox field..it's working fine..How i change dropdown field instead of input box..?

views.php
_____________
<div class="leftsection" >
&lt;?php echo form_open('../product_search/search_all'); $var = 0; if (isset($var)) { ?&gt;
&lt;?php $search = array('name'=>'search','id'=>'search','value'=>'');?&gt;
&lt;?php $search2 = array('name'=>'search2','id'=>'search2','value'=>'');?&gt;
&lt;?php $search3 = array('name'=>'search3','id'=>'search3','value'=>'');?&gt;
<p><label>Search By Card Code<br /></label>&lt;?php echo form_input($search); ?&gt;</p>
<p><label>Search By Type<br /></label>&lt;?php echo form_input($search2); ?&gt;</p>
<p><label>Search By Color<br /></label>&lt;?php echo form_input($search3); ?&gt;</p>
<p>&lt;input type=submit value='Search' /&gt;&lt;/p>
&lt;?php } form_close();?&gt;
________________

model.php
________________
function get_search($limit = NULL, $offset = NULL)
{
$match3 = $this->input->post('search3');
$this->db->like('color',$match3);
$match2 = $this->input->post('search2');
$this->db->like('type',$match2);
$match = $this->input->post('search');
$this->db->like('code',$match);
$query = $this->db->limit($limit, $offset)->get('products');
return $query->result();
}




Theme © iAndrew 2016 - Forum software by © MyBB