title: Change read status in MYSQL based on the click status in HTML/JS
body: <p>I've created an inbox which would fetch the messages from mysqldb.</p>
  
  <p>I need to differentiate between read and unread e-mails, which I'm trying to achieve through inline-styling in the row.
  I'm trying to do that as soon as a user clicks on the e-mail and opens it, change the status in mysqldb for readstatus flag = "YES", which is "NO" by default.</p>
  
  <p>Howver, it works only for the first row. </p>
  
  <h2>View</h2>
  
  <pre><code>    &lt;form action="&lt;?php echo BASEURL; ?&gt;home/movetotrash" method="POST" id="emailform" enctype="multipart/form-data"&gt;
      &lt;center id="msg"&gt;&lt;/center&gt;
      &lt;table align="center" cellpadding="10" border="1" class="mailbox"&gt;
  
  
          &lt;tr class="headrow"&gt;
              &lt;th&gt;Select&lt;/th&gt;
              &lt;th&gt;From&lt;/th&gt;
              &lt;th&gt;E-mail&lt;/th&gt;
              &lt;th&gt;Subject&lt;/th&gt;
              &lt;th&gt;Date&lt;/th&gt;
  
          &lt;/tr&gt;
          &lt;?php
              $id="";
              $read = 0;
              $unread = 0;8*****-
              foreach($row as $alldata)
              {
                  $id = $alldata-&gt;ID;
                  if($alldata-&gt;READSTATUS=="YES"){
                  $read++;
                  echo "&lt;tr id='".$alldata-&gt;ID."' bgcolor='lightgray'&gt;";
                  }else{
                      $unread++;
                      echo "&lt;tr id='".$alldata-&gt;ID."' bgcolor='white'&gt;";
                  }
                      echo "&lt;td&gt;&lt;input type='checkbox' name='select[]' id='select' value=".$id." onclick='enablebtn()'&gt;&lt;/td&gt;";
                      echo "&lt;td class='mailcell' name='name[]' id='nameclick'&gt;".$alldata-&gt;NAME."&lt;/td&gt;";
                      echo "&lt;td class='mailcell' name='sender[]' id='nameclick'&gt;".$alldata-&gt;SENDER."&lt;/td&gt;";
                      echo "&lt;td class='mailcell' name='subject[]' id='nameclick'&gt;".$alldata-&gt;SUBJECT."&lt;/td&gt;";
                      echo "&lt;td class='mailcell' name='date[]' id='nameclick'&gt;".$alldata-&gt;DATE."&lt;/td&gt;";
  
                  echo "&lt;/tr&gt;";
              }
          ?&gt;
      &lt;/table&gt;
  
  &lt;button type="submit" class="btn-primary" name='movetotrash' id="movetotrash" disabled"&gt;Delete&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <h2>Controller</h2>
  
  <pre><code>public function showemail()
  {
      $data['row'] = $this-&gt;user_model-&gt;inboxdb();
      $data['sentemail'] = $this-&gt;user_model-&gt;sentemaildb();
      $data['draftemail'] = $this-&gt;user_model-&gt;draftemaildb();
      $data['trashemail'] = $this-&gt;user_model-&gt;trashemaildb();
      $this-&gt;load-&gt;view('index',$data);
      $data['emaildata'] = $this-&gt;user_model-&gt;showemaildb();
      $id = $data['emaildata']-&gt;ID;
      $this-&gt;user_model-&gt;changereadstatus($id);
      $this-&gt;load-&gt;view("showemail", $data);
      $this-&gt;load-&gt;view('footer');
  }
  </code></pre>
  
  <h2>Model</h2>
  
  <pre><code>public function changereadstatus($id)
      {
          $sql="update email set READSTATUS='YES' where ID='$id'";
          $res = $this-&gt;db-&gt;query($sql);
          return true;
      }
  </code></pre>