Trying to update college profile which contains all the college info in the database, Some records are manually filled in by data entry, some records have to be updated by the college admin or super admin.
The issue is when I insert an array (Facilities[ ]) into the Db it inserts without any errors, but when i update the same it gives me an error.
The Insertion was done through another controller with insert statement
$company_id = $this->companies_model->add_company($company_array);
which works flawlessly, But update function gives me this error
Error Number: 1054
Unknown column 'Array' in 'field list'
UPDATE pp_companies SET facilities = Array, company_description = 'Established in the year....', company_join = 'Why Join us', WHERE ID = '201'
Filename: C:\xampp\htdocs\jobportal\jp_sys\database\DB_driver.php
Line Number: 287
Facilities = 'Array'? any idea how this shows?
Array ( [0] => Engineering [1] => Management )
sends the value when i check through
print_r($this->input->post('facilities'));
But it doesnt get updated in the table
View
<div class="input-group <?php echo (form_error('company_description'))?'has-error':'';?>">
<label class="input-group-addon">College<br> Description <span>*</span></label>
<textarea class="form-control" name="company_description" id="company_description" rows="8" cols="30" ><?php echo $company_description; ?></textarea>
<?php echo form_error('company_description'); ?> </div>
<div class="input-group <?php echo (form_error('company_join'))?'has-error':'';?>">
<label class="input-group-addon">Why join <br> our College? <span>*</span></label>
<textarea class="form-control" name="company_join" id="company_join" rows="8" cols="30" ><?php echo $company_join; ?></textarea>
<?php echo form_error('company_join'); ?> </div>
<?php echo $facilities ?>
<div class="input-group boxwraper <?php echo (form_error('facilities'))?'has-error':'';?>">
<label class="input-group-addon">Facilities Offered <span></span></label>
<select name="facilities[]" class="js-example-tags" multiple="multiple">
<option value="Library" >Library</option>
<option value="Gym" >Gym</option>
<option value="Canteen" >Canteen</option>
.
.
</select>
</div>
<script type="text/javascript">
$(".js-example-tags").select2({
tags: true
})
</script>
Model
public function add_company($data){
$return = $this->db->insert('pp_companies', $data);
if ((bool) $return === TRUE) {
return $this->db->insert_id();
} else {
return $return;
}
}
public function update_company($id, $data){
$this->db->where('ID', $id);
$return=$this->db->update('pp_companies', $data);
return $return;
}
Controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Edit_College extends CI_Controller {
public function index()
{
$row = $this->employers_model->get_employer_by_id($this->session->userdata('user_id'));
$data['row'] = $row;
$data['title'] = $row->company_name.' - Edit Profile';
$this->form_validation->set_rules('facilities[]', 'Facilities', 'trim|required|strip_all_tags');
$this->form_validation->set_rules('company_description', 'Company Description', 'trim|required|strip_all_tags|secure');
$this->form_validation->set_rules('company_join', 'Company Join', 'trim|required|strip_all_tags|secure');
$data['facilities'] = (set_value('facilities'))?set_value('facilities'):$row->facilities;
$data['company_description'] = (set_value('company_description'))?set_value('company_description'):$row->company_description;
$data['company_join'] = (set_value('company_join'))?set_value('company_join'):$row->company_join;
if ($this->form_validation->run() === FALSE) {
$this->load->view('employer/edit_company_profile_view',$data);
return;
}
//for facility addition into db
$arrcategory1 = $this->input->post('facilities');
foreach($arrcategory1 as $val1)
{
$categoryarr1 = $categoryarr1 . $val1. ",";
}
$categoryarr1 = substr(trim($categoryarr1), 0, -1); //rtrim($categoryarr,",")
$company_array = array(
'facilities'=> $arrcategory1,
'company_description' => $this->input->post('company_description'),
'company_join' => $this->input->post('company_join'),
$this->companies_model->update_company($row->company_ID, $company_array);
$this->session->set_flashdata('msg', '<div class="alert alert-success">×<strong>Success!</strong> Your company profile has been updated.</div>');
$this->session->set_userdata('slug',$company_slug);
redirect(base_url('employer/edit_college'));
}
}
Related
i have a form which included an select dropdown which is id_constructor, the problem is the all remaining data is updated into the database except the id_constructor, my table looks like this :
teams
id_team
name
id_constructor
created_at
modified_at
And here is my code :
Controller :
$this->load->database();
$this->load->helper('form');
$this->load->library(array('form_validation'));
$this->load->model('back-end/m_masterteam','teams');
$this->load->model('back-end/m_masterconstructors','constructors');
public function edit($id_team)
{
$data['teams_data'] = $this->teams->getTeam($id_team);
$data['constructors_data'] = $this->constructors->getAllConstructor();
$this->load->view('back-end/template/header');
$this->load->view('back-end/edit-team', $data);
$this->load->view('back-end/template/footer');
}
public function updateTeam()
{
$id_team = $this->input->post('id_team');
$name = $this->input->post('name');
$id_constructor = $this->input->post('id_constructor');
$modified_at = $this->input->post('modified_at');
$data = array(
'id_team' => $this->input->post('id_team'),
'name' => $this->input->post('name'),
'id_constructor' => $this->input->post('id_constructor'),
'modified_at' => date('Y-m-d H:i:s')
);
// print_r($data);exit();
$this->teams->update($data, $id_team);
echo json_encode(array("status" => TRUE));
redirect('admin-page/MasterTeam/');
}
Model :
var $table = 'teams';
var $column = array('name','id_constructor','created_at','modified_at');
var $order = array('teams.name' => 'desc');
function update($data, $id_team)
{
$this->db->where('id_team', $id_team);
$this->db->update('teams', $data);
}
And here is the view for the select option :
<form action="<?php echo base_url('admin-page/MasterTeam/updateTeam') ?>" method="post">
<div class="form-group row">
<label for="inputPassword" class="col-sm-2 col-form-label">Constructor</label>
<div class="col-sm-10">
<select class="form-control" name="id_constructor">
<?php foreach($constructors_data as $row)
{?>
<option value="<?php echo $teams_data->id_constructor; ?>"<?php if($row->id_constructor==$teams_data->id_constructor) echo 'selected="selected"';?>><?php echo $row->name; ?></option>
<?php
}
?>
</select>
</div>
</div>
And here is the result for print_r() :
Array ( [id_team] => 16 [name] => test21 [id_constructor] => 3
[modified_at] => 2022-02-28 13:42:11 )
all data except the id_constructor is updated in the database, anyone know the solution? any help is really appreciated. thank you!.
I have table ingredient w/c consist of(ingredient_id,name),category w/c consist of(category_id,name) and category_ingredients w/c consist of(ingredient_id,category_id). I create a form for adding many ingredients by category and i want to check if 1 or more ingredients already exist then i will only have to get the id's of the ingredient and then the other ingredients that don't exist will be inserted in my db. can u guys help me pls?
Here's my code:
VIEW:
<?php echo form_open('dashboard/uploadIngredients', 'class="form-horizontal" enctype="multipart/form-data"'); ?>
<div class="form-group">
<div class="col-sm-10">
<select required class="form-control" name="ingredient_category">
<option value="" selected disabled>Select Ingredient Category</option>
<option value="All">All</option>
<?php foreach($this->products_model->getCategory() as $row): ?>
<option value="<?php echo $row->category_id ?>"><?php echo $row->category_name; ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<textarea class="form-control" name="ingredients" rows="5" placeholder="Ingredients (EX. onion, oil, pasta)" required></textarea>
</div>
</div>
<div class='form-group'>
<div class="col-sm-10">
<button class="btn btn-lg btn-positive" type="submit"><i class="glyphicon glyphicon-ok"></i> Save Ingredient</button>
</div>
</div>
<?php echo form_close(); ?>
CONTROLLER:
public function uploadIngredients()
{
foreach(explode(',', $this->input->post('ingredients')) as $key => $value)
{
$saveData[] = array('ingredient_id' => null,
'name' => trim($value)
);
}
$ingredient_id = $this->products_model->saveIngredients($saveData);
foreach (explode(',', $this->input->post('ingredient_category')) as $key => $value)
{
foreach ( $ingredient_id as $key => $str ){
$joinData[] = array(
'ingredient_id' => $str,
'category_id' => intval($value)
);
}
//var_dump($joinData); die();
$this->products_model->saveCategoryIngredients($joinData);
redirect('dashboard/add_ingredients');
}
}
MODEL:
public function saveIngredients($ingredient_id)
{
foreach($ingredient_id as $row => $value) {
$query=$this->db->where('ingredient_id', $value->ingredient_id);
$this->db->insert('ingredient', $value);
$insert_id[] = $this->db->insert_id();
}
return $insert_id;
}
public function saveCategoryIngredients($data)
{
foreach($data as $row => $value)
{
$this->db->insert('category_ingredient', $value);
$insert_id[] = $this->db->insert_id();
}
return $insert_id;}
}
You just have to add a function to your model, like this :
<?php
public function getIngredientByName($name) {
return $this->db
->from('ingredient I')
->where('I.name', $name)
->get()->row(); //Will return the row of ingredient if ingredient exists, else null
}
And in your controller :
<?php
foreach(explode(',', $this->input->post('ingredients')) as $key => $value)
{
if (!$this->products_model->getIngredientByName($value)) {
$saveData[] = array(
'ingredient_id' => null,
'name' => trim($value)
);
}
}
Thanks Gwendal for answering this question i am modifying this answer a bit to prevent duplicate inserts e.g.:- if user inserts SuGar CaNe but we have in our database Sugar Cane then the with answer's code we will have 2 sugar cane to avoid these type of inserts we can use this code for model
<?php
public function getIngredientByName($name) {
return $this->db
->from('ingredient I')
-> where("( REPLACE( LOWER(I.name), ' ', '') LIKE '".strtolower(preg_replace('/\s+/', '', $name)) ."%')")
->get()->row(); //Will return the row of ingredient if ingredient exists, else null
}
for controller same as
<?php
foreach(explode(',', $this->input->post('ingredients')) as $key => $value)
{
if (!$this->products_model->getIngredientByName($value)) {
$saveData[] = array(
'ingredient_id' => null,
'name' => trim($value)
);
}
}
OK, so I have looked everywhere for a solution to my problem but found none so far.My code looks like this.I have created a dynamic view page in which edit and add views are loaded dynamically.But the problem arises when i try to retain the value of select dropdown during editing.I would be grateful if someone could help me out.
View
<div class="panel-body">
<div class="row">
<div class="col-lg-6">
<?php if(#$patient_info){
echo '<h1 class="page-header">Edit Patient</h1>';
}else{
echo '<h1 class="page-header">Add Patient</h1>';
}
?>
<?php if($this->session->flashdata('error')){ ?>
<div class="alert alert-danger"><?php echo $this->session->flashdata('error'); ?></div>
<?php } ?>
<?php if($this->session->flashdata('erroredit')){ ?>
<div class="alert alert-danger"><?php echo $this->session->flashdata('erroredit'); ?></div>
<?php } ?>
<?php //echo validation_errors('<div class="alert alert-danger">','</div>'); ?>
<form role="form" method="post" action="<?php echo isset($patient_info) ? site_url('home/patient/edit') .'/' .$patient_info->patientID : site_url('home/patient/new'); ?>">
<div class="form-group">
<?php echo form_error('pname', '<div class="alert alert-danger">', '</div>'); ?>
<label for="pname">Patient Name</label>
<input class="form-control" placeholder="Enter Patient Name" name="pname" value="<?php echo isset($patient_info) ? $patient_info->patientName : ''; ?>">
</div>
<!-- Dropdown menu for selecting clinic -->
<div class="form-group">
<label for="select">Select Clinic Name</label>
<select class="form-control" name="selectClinic">
<option value="none">Select Clinic Below</option>
<?php foreach($allclinic as $key=>$clinic){ ?>
<!--<?php //foreach($clinicByPatient as $clin): ?>-->
<option value="<?php $clinic->clinicID; ?>"
<?php if(isset($patient_info)){
echo 'selected="selected"';
}
?>
>
<?php echo $clinic->clinicName; ?>
</option>
<?php //endforeach; ?>
<?php } ?>
</select>
</div>
<!-- Select Clinic ends-->
<div class="form-group">
<label for="select">Select Dentist</label>
<select class="form-control" name="selectDentist">
<option value="">Select Dentist</option>
<?php foreach($dentistdet as $key=>$dentist){ ?>
<option value="<?php echo $did = $dentist->dentistID;?>"><?php echo $dentist->dentistName; ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary btn-lg btn-block" name="submit" value="<?php echo isset($patient_info) ? 'Update Patient' : 'Add Patient'; ?>" >
</div>
</form>
<div class="form-group">
<input type="submit" class="btn btn-danger btn-lg btn-block" value="Cancel">
</div>
Edit controller
public function edit(){
$id = $this->uri->segment(4);
$this->load->library('form_validation');
$this->load->model('clinic_model');
$this->load->model('dentist_model');
$data['patient_info'] = $this->patient_model->getPatientById($id);
$data['clinicByPatient'] = $this->patient_model->getPatientByClinic();
$data['allclinic'] = $this->clinic_model->getAllClinics();
// $data['clinicdet'] = $this->patient_model->getPatientByClinic();
if($_POST){
$this->form_validation->set_rules('pname', 'Patient Name', 'trim|required|xss_clean');
$this->form_validation->set_rules('paddress', 'Patient Address', 'trim|required|xss_clean');
$this->form_validation->set_rules('pcontact', 'Patient Contact', 'trim|required|xss_clean');
if($this->form_validation->run()== FALSE){
$data['subview'] = 'patient/patient_new';
$this->load->view('includes/layout', $data);
}else{
$patientname = $this->input->post('pname');
$patientaddress = $this->input->post('paddress');
$patientcontact = $this->input->post('pcontact');
$select = $this->input->post('selectClinic');
$option = $this->input->post('selectDentist');
$edited = $this->patient_model->editpatient($id, $patientname, $patientaddress, $patientcontact, $select, $option);
if($edited){
$this->session->set_flashdata('successedit', 'Successfully updated the record');
redirect('home/patient');
}
}
}else{
$data['subview'] = 'patient/patient_new';
$this->load->view('includes/layout',$data);
}
}
Model looks like this
<?php if( ! defined('BASEPATH')) exit('No direct script access allowed');
class Patient_model extends CI_Model{
public function countPatients(){
$countPatient = $this->db->count_all('patient');
return $countPatient;
}
public function getallpatients(){
$query = $this->db->get('patient');
if($query->num_rows()>0){
return $query->result();
}
else{
return FALSE;
}
}//getallpatients function ends
public function getPatientByClinic(){
$this->db->select('*');
$this->db->from('patient');
$this->db->join('clinic', 'patient.clinicID = clinic.clinicID', 'left');
$this->db->join('dentist', 'patient.dentistID = dentist.dentistID', 'left');
$query = $this->db->get();
if($query->num_rows>0){
return $query->result();
}
}
public function addPatientByClinic($patientname, $patientadd, $patientcontact, $select, $option){
$data = array(
'patientName' => $patientname,
'patientAddress' => $patientadd,
'patientContact' => $patientcontact,
'clinicID' => $select,
'dentistID' => $option
);
return $this->db->insert('patient',$data);
}// method ends
public function deletePatient($id){
$verifyID = array('patientID' => $id);
// $affRows = $this->db->affected_rows();
// $obj = new Patient_model;
if($verifyID){
$this->db->where($verifyID);
$this->db->delete('patient');
if($this->db->affected_rows()){
return TRUE;
}
}
}
public function editpatient($id, $patientname, $patientaddress, $patientcontact, $select, $option){
$data = array(
'patientName' => $patientname,
'patientAddress' => $patientaddress,
'patientContact' => $patientcontact,
'clinicID' => $select,
'dentistID' => $option
);
$query = $this->db->where('patientID', $id)
->update('patient', $data);
if($query){
return true;
}
}//method ends
public function getPatientById($id){
$query = $this->db->where('patientID', $id)
->get('patient');
return $query->row();
}
}//class ends
?>
In the code for your select box, you aren't actually echoing $clinic->clinicID. Thus, when the form is submitted, the value will be empty.
You also need to be careful with how you are choosing which select element will be selected by default - you aren't comparing with anything that will change within the loop. Should you be checking against $clinic->clinicID?
im still learning codeigniter and have come up with a problem. That is
You must use the "set" method to update an entry.
I am trying to update a table : product which contains product_name, product_desc etc columns below are my controller ,view and model .. i cannot figure out what am i doing wrong .. I always checked out print_r($array); it gives me an empty array ... although i do get product details displayed in the input fields on the link : ci/index.php/admin/product/1 ..
posting half code for view as the view code is long ..
Controller :
//**** For editing product ****//
public function edit_products(){
$data = array ('product_name'=>$this->input->post('product_name'),
'product_desc'=>$this->input->post('product_desc'),
'product_stock'=>$this->input->post('product_stock'),
'product_sku'=>$this->input->post('product_sku'),
'inventory_date'=>$this->input->post('inventory_date'),
'product_price'=>$this->input->post('product_price'),
'featured_product'=>$this->input->post('featured_product'),
'best_seller'=>$this->input->post('best_seller'),
'brand_id'=>$this->input->post('brand_id'),
);
$upd_pr = $this->mainmodel->update_product($_POST);
if($upd_pr){
$this->session->set_flashdata('messages', 'Updated Sucessfully');
redirect('admin/editing_products');
}else{
$this->session->set_flashdata('error', 'Updation Failed');
redirect('admin/editing_products');
}
}
public function editing_products(){
$data['product']=$this->mainmodel->set_pro2();
//$data['images'] = $this->products->images($id);
$data['content']='admin/edit_products';
$this->load->view('admin/main',$data);
}
Model :
/*for update Product*/
public function update_product($array){
extract($array);
//print_r($array);
//die;
$this->db->update('product',array('product_name'=>$product_name,'product_desc'=>$product_desc,'inventory_date'=>$inventory_date,'product_price'=>$product_price,'featured_product'=>$featured_product,'best_seller'=>$best_seller,'brand_id'=>$brand_id));
$this->db->update('product');
return ;
}
function set_pro2(){
$q = $this->db->query('SELECT * FROM product,product_image,category_product WHERE product.product_id = category_product.product_id AND product.product_id = 1 LIMIT 1');
if($q->num_rows() > 0){
foreach($q->result() as $row){
$data[] = $row;
}
return $data;
}
}
View :
<form class="form-horizontal form-row-seperated" enctype="multipart/form-data" action="<?php echo site_url('admin/edit_products') ?>" method="post">
<div class="form-group">
<?php foreach($product as $pro){ ?>
<label class="col-md-2 control-label">Name:<span class="required">
* </span>
</label>
<div class="col-md-10">
<input type="text" class="form-control" name="product_name" placeholder="" value="<?php echo $pro->product_name; ?>">
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Description: <span class="required">
* </span>
</label>
<div class="col-md-10">
<input type="text" class="form-control" name="product_desc" value="<?php echo $pro->product_desc; ?>">
</div>
</div>
In some cases codeigniter updates / inserts require this->db->set if in array. I also would not recommend placing two db->update to the same table as you have added on model.
Active record guide http://www.codeigniter.com/user_guide/database/active_record.html
Update
// $brand_id = 0, $data are from the edit function on controller
public function name($brand_id = 0, $data) {
$product_name = $this-input->post('product_name');
$product_desc = $this-input->post('product_desc');
$inventory_date = $this-input->post('inventory_date');
$product_price = $this-input->post('product_price');
$featured_product = $this-input->post('featured_product');
$best_seller = $this-input->post('best_seller');
$data = array(
'product_name'=> $product_name,
'product_desc'=> $product_desc,
'inventory_date'=>$inventory_date,
'product_price'=>$product_price,
'featured_product'=> $featured_product,
'best_seller'=> $best_seller,
'brand_id'=> $this->uri->segment(what_ever)
);
$this->db->set($data);
$this->db->update('product');
}
Or insert
$data = array(
'product_name'=> $product_name,
'product_desc'=> $product_desc,
'inventory_date'=>$inventory_date,
'product_price'=>$product_price,
'featured_product'=> $featured_product,
'best_seller'=> $best_seller,
'brand_id'=>$brand_id
);
$this->db->set($data);
$this->db->insert_id();
$this->db->insert('product');
Post Update
Set routes $route['function/edit/(:any)'] = 'folder/products_list/edit/$1';
If need to update a product you need to set a function called edit on the
Model Get
public function model_get_products() {
return $this->db->get($this->db->dbprefix . 'products')->result_array();
}
Controller for uri segment help http://www.codeigniter.com/user_guide/libraries/uri.html
public function edit() {
Form validation
$this->load->library('form_validation');
$this->form_validation->set_rules('what ever');
if ($this->form->validation->run() == TRUE) {
$this->load->model('folder/model_update_product');
//Example uri segment admin/product_list/edit/id_number $this->uri->segment('4')
$this->model_update_product->name($this->uri->segment('what_ever_is'), $this->input->post())
redirect('function/product_list');
} else {
// Load Your Form View i.e. $this->get_form();
}
}
public function index() {
$this->load->model('folder/model_get_products');
$results = $this->model_get_products->get();
$data['products'] = array();
//Example uri segment admin/product_list/edit/id_number $this->uri->segment('4')
// Add What Else You Need to here and then you can add it to view
foreach($results as $result) {
$data['products'][] = array(
'brand_id' => $result[brand_id],
'edit' => site_url('controller_name/edit'). '/' .$result[brand_id] // site_url must match what you set in routes for edit.
);
}
return $this->load->view('folder/products_list', $data);
}
public function get_form() {
//Example uri segment admin/product_list/edit/id_number $this->uri->segment('4')
// Make sure you set another model function in your get model where can get by id.
$product_info = $this->get_products_by_id->get($this->uri->segment('4'));
$product_name = $this->input->post('product_name');
if (isset($product_name)) {
$data['product_name'] = $product_name; // for name="" in input
} elseif (!empty($product_info)) {
$data['product_name'] = $product_info['product_name']; // for value="" in input
} else {
$data['product_name'] = '';
}
$this->load->view('folder/product_form', $data);
product form contents
}
view product list
<form>
<table>
<thead>
</thead>
<tbody>
<?php if ($products) { ?>
<?php foreach ($products as $product) { ?>
<tr>
<td><?php echo $product['brand_id'];?></td>
<td> Edit Product</td>
</tr>
<?php } ?>
<?php } ?>
</tbody>
</table>
</form>
I have two select boxes, if I select an option, it will give me results according to the options and then the results will display in the 2nd select box. How can I do this?
I think, I have to do a onchange function but I don't know how can I get data from controller in JavaScript .
class StockInController extends MY_Controller {
function index(){
$data['main_content'] = 'stockInView';
$this->load->model('supplierModel');
$query = $this->supplierModel->getAllSuppliers();
if ($query){
$data['records1'] = $query;
}
$this->load->model('categoryModel');
$query = $this->categoryModel->getAllCategories();
if ($query){
$data['records2'] = $query;
}
$this->load->model('itemsModel');
$query = $this->itemsModel->getAllItems();
if ($query){
$data['records3'] = $query;
}
$this->load->view('dashboardTemplate/template',$data);
}
function addStockIn(){
//getting parameters from view
$data = array(
'item_name' => $this->input->post('item_name'),
'cat_id' => $this->input->post('cat_id')
);
//$is_ajax = $this->input->post('ajax'); //or use this line
//$this->input->is_ajax_request();
$result = array();
$this->load->model('stockInModel');
$query = $this->stockInModel->addStocktoDB($data);
if ($query){ //&& any other condition
$result['res'] = 1;//process successful - replace 1 with any message
} else {
$result['res'] = 0;//process failed - replace 0 with any message
}
echo json_encode($result);//at the end of the function.
}
}
Here is the View:
<div class="control-group">
<label for="selsear" class="control-label">Select a Category</label>
<div class="controls">
<select name="select1" id="seslsear" class='cho'>
<option id = "y" value="0">--Select--</option>
<?php foreach($records2 as $r) { ?>
<option value="<?=$r->cat_id?>"><?=$r->cat_name?></option>
<?php } ?>
</select>
</div>
</div>
<div class="control-group">
<label for="selsear" class="control-label">Select an item</label>
<div class="controls">
<select name="select1" id="selsear" class='cho'>
<option id = "y" value="0">--Select--</option>
<?php foreach($records3 as $r) { ?>
<option value="<?=$r->item_id?>"><?=$r->item_name?></option>
<?php } ?>
</select>
</div>
</div>
You will have to write a function on-change of select box & feed data in success of ajax
$('#selsear').change(function() {
var form_data = {
item_name: $('#item_name').val(),
cat_id: $('#selsear').val()
};
$.ajax({
url:'controller_name/function_name',
data:form_data,
datatype:'application/json',
success:function(data){
$.each(data,function(i){
htmlString="<option value='"+data[i]['item_id']+"'>'"+data[i]['item_name']+"'</option>"
});
$("#selsear").html(htmlString);
}
});
The controller function name is the name of function which retrieves data from controller.
I hope this will help you!