title: I want to pass id from view to controller in Codeigniter using Ajax and Update a Dropdown Selection in DB
body: <p>I wanted to pass ID of each row from table and pass it to controller using AJAX and wanted to  update the Dropdown Selection of that row in DB.</p>
  <p>The Selection what i make in Dropdown is passed to the controller but not sure how to update in DB based on its each row condition. A help would be much Appreciated!!!</p>
  <p><strong>Below is the Screenshot of my UI</strong></p>
  <p>Screen Shot with ID and Dropdown</p>
  <p><img src="https://i.stack.imgur.com/rBS7m.png" alt="Screen Shot with ID and Dropdown" /></p>
  <p><strong>View File</strong></p>
  <pre><code>&lt;?php if( is_array( $fbrecords ) &amp;&amp; count( $fbrecords ) &gt; 0 ) 
  foreach($fbrecords as $r) { ?&gt;
      &lt;tr class=&quot;idrow&quot;&gt;
          &lt;td id=&quot;tdname&quot; &gt;&lt;!-- style=&quot;display:none;&quot; --&gt; &lt;?php echo $r-&gt;id; ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $r-&gt;fullname; ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $r-&gt;email; ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $r-&gt;mobile; ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $r-&gt;message; ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $r-&gt;jtime; ?&gt;&lt;/td&gt;
          &lt;td&gt; &lt;?php  $data=array(
          
  'name'=&gt;'status',
  'row' =&gt; '12px',
  'id' =&gt; 'status',
  'selected'=&gt;'none',
  'class'=&gt;'statusClass'
  
  );
  $data_status = array(
  'none' =&gt; 'none',
  'A&amp;A' =&gt; 'Attended &amp; Acted',
  'YTA' =&gt; 'Yet to Attend',
  );
  echo form_dropdown($data, $data_status, set_value('status')); ?&gt; &lt;/td&gt;
          &lt;td&gt;&lt;button type=&quot;button&quot; class=&quot;btn btn-sm btn-success emlbtn&quot; &gt; Reply to &lt;?php $fname=explode(&quot; &quot;,$r-&gt;fullname); echo $fname[0]; ?&gt;&lt;/button&gt;
          
  </code></pre>
  <p><strong>AJAX Code</strong></p>
  <pre><code>$(document).ready(  function() {
  $(&quot;.statusClass&quot;).change(function(event) {
  event.preventDefault();
  //var dropDown = document.getElementById(&quot;status&quot;);
  //var status =  dropDown.options[dropDown.selectedIndex].value;
  var status = $(this).val(); 
  console.log(status);
  jQuery.ajax({
  type: &quot;POST&quot;,
  url: &quot;&lt;?php echo base_url(); ?&gt;&quot; + &quot;index.php/user_authentication/user_data_status_submit&quot;,
  dataType: 'json',
  data: {status:status},
  success: function(data){
  if (result)
  {
  alert(&quot;success&quot;);
  }
  }
  
  });
  });
  }); 
  </code></pre>
  <p><strong>Controller</strong></p>
  <pre><code>public function user_data_status_submit(){
  
  $data = array(
  'status' =&gt; $this-&gt;input-&gt;post('status'),
  'id'
  );
  //Either you can print value or you can send value to database
  echo json_encode($data);
  $this-&gt;login_database-&gt;feedback_update($data);
  
  }
  </code></pre>
  <p><strong>Update Function in Model</strong></p>
  <pre><code>public function feedback_update($data){
  
  $this-&gt;db-&gt;set($data); 
  $this-&gt;db-&gt;where(&quot;id&quot;, $old_id);
  $this-&gt;db-&gt;update('feedback_table', $data);
  
  }
  </code></pre>