I have to make a select and when user choose option from it, it should be displayed data from database based on this select. I can't use submit. It only should be displayed this select and when option is selected, to show data from this select. I'm new to jQuery and I can't do it. My view is:
<select name="myselect" id="myselect" >
<option value=''" . set_select('size, '') . " > </option>
<option value="1" <?php echo set_select('size', '1'); ?> role="menuitem">1</option>
<option value="2" <?php echo set_select('size', '2'); ?> role="menuitem">2</option>
<option value="3" <?php echo set_select('size', '3'); ?> role="menuitem">3</option>
<option value="4" <?php echo set_select('size', '4'); ?> role="menuitem">4</option>
</select>
My model is:
<?php
public function average_price_by_week() {
$this->db->select(*);
$this->db->from('items');
$this->db->where('size', $size); //this $size should be value from select that user has selected
$query=$this->db->get();
return $query->result_array();
}
?>
Try this, It may help you.
I have used
JQuery Ajax
. Also includeJQuery library
before use the below code.Controller:
Model:
Thanks.