title: Update rows in MySQL table with CodeIgniter
body: <p>So I'm new to PHP and MySQL generally, and MVC applications. Forgive me if this is a question that has been answered already, I couldn't find anything that was crystal clear and showed the complete MVC flow of this.</p>
  
  <p>So I have an HTML table full of inputs populated by data in a, I generate a form for each row as a separate table, and a submit button for each. I want the update button to update only the row associated with the generated form.</p>
  
  <p>If remove <code>this-&gt;db-&gt;where('id', $id);</code> from the model it updates all rows in the table with the same info, with it present nothing is updated.</p>
  
  <p>Any help or an alternative method for achieving this would be most appreciated. The controller function is also not pretty bad I think.</p>
  
  <p>Thank you.</p>
  
  <p><strong>VIEW</strong></p>
  
  <pre><code>&lt;?php foreach($log-&gt;result() as $row): ?&gt;
  &lt;?=form_open('hq/update_entry');?&gt;
      &lt;table class="editLog"&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;?php 
                  $data = array(
                      'name' =&gt; 'no',
                      'value' =&gt; $row-&gt;no
                  );
                  echo form_input($data);
                  ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php 
                  $data = array(
                      'name' =&gt; 'date',
                      'value' =&gt; $row-&gt;date
                  );
                  echo form_input($data);
                  ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php 
                  $data = array(
                      'name' =&gt; 'artist',
                      'value' =&gt; $row-&gt;artist
                  );
                  echo form_input($data);
                  ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php 
                  $data = array(
                      'name' =&gt; 'title',
                      'value' =&gt; $row-&gt;title
                  );
                  echo form_input($data);
                  ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php 
                  $data = array(
                      'name' =&gt; 'long',
                      'value' =&gt; $row-&gt;long
                  );
                  echo form_input($data);
                  ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php 
                  $data = array(
                      'name' =&gt; 'lat',
                      'value' =&gt; $row-&gt;lat
                  );
                  echo form_input($data);
                  ?&gt;&lt;/td&gt;
                  &lt;td&gt;
              &lt;?php
                  echo form_hidden('id', $row-&gt;id);
                  $data = array(
                      'class' =&gt; 'updateSubmit',
                      'value' =&gt; '✚'
                  );
                  echo form_submit($data);
              ?&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;?=form_close();?&gt;
  </code></pre>
  
  
  
  <p><strong>CONTROLLER</strong></p>
  
  <pre><code>function update_entry()
  {
      $this-&gt;load-&gt;model('update_entry_model');
  
      if($query = $this-&gt;update_entry_model-&gt;update())
      {
          $this-&gt;index();
      }
      else
      {
          redirect('hq');
      }
  }
  </code></pre>
  
  <p><strong>MODEL</strong></p>
  
  <pre><code>&lt;?php
      class Update_entry_model extends CI_Model {
          function update()
          {
              $data = array(
                  'no' =&gt; $this-&gt;input-&gt;post('no'),
                  'date' =&gt; $this-&gt;input-&gt;post('date'),
                  'artist' =&gt; $this-&gt;input-&gt;post('artist'),
                  'title' =&gt; $this-&gt;input-&gt;post('title'),
                  'long' =&gt; $this-&gt;input-&gt;post('long'),
                  'lat' =&gt; $this-&gt;input-&gt;post('lat')
              );
              $this-&gt;db-&gt;where('id', $id);
              $this-&gt;db-&gt;update('entries', $data);
          }
      }
  </code></pre>