title: checking data exists or not when editing the data in codeigniter
body: <p>I have a problem when editing data from the database. </p>
  
  <p>this is my controller function </p>
  
  <pre><code>public function cek_nip_update()
  {
      $this-&gt;load-&gt;model("model_dosen");
      $unique_id = $this-&gt;input-&gt;post('unique_id');
      $nip = $this-&gt;input-&gt;post('nip');
      $hasil_nip = $this-&gt;model_dosen-&gt;cek_nip($nip);
      $hasil_unik = $this-&gt;model_dosen-&gt;cek_unik($unique_id);
      $hasil_cek = $this-&gt;model_dosen-&gt;cek_nipp($nip,$unique_id);
      if (count($hasil_nip)==0)
      {
          echo 'gada'; 
      }
      else
      {
          if ($hasil_nip==$hasil_cek) {
              echo "gada";
          }
          else
          {
              echo "ada";
          }
      }
  }
  </code></pre>
  
  <p>and this is my model </p>
  
  <pre><code>public function cek_nip($nip)
      {
          $cek = $this-&gt;db-&gt;query("select nip from detail_dosen where nip='$nip'");
          return $cek-&gt;result();
      }
  
      public function cek_unik($unique_id)
      {
          $cek = $this-&gt;db-&gt;query("select nip from detail_dosen where unique_id='$unique_id'");
          return $cek-&gt;result();
      }
  
      public function cek_nipp($nip, $unique_id)
      {
          $cek = $this-&gt;db-&gt;query("select nip from detail_dosen where nip='$nip' and unique_id='$unique_id'");
          return $cek-&gt;result();
      }
  </code></pre>
  
  <p>The result I want is </p>
  
  <ol>
  <li>When I type nip not exist, the span I make will not show something</li>
  <li>When I type nip exits in the input, but with the same unique_id, the span will not show something</li>
  <li>When I type nip exits in the input, with the different unique_id, the span will show "NIP is used by the other"</li>
  </ol>
  
  <p>My code just works with number 1 condition, but when I type nip exists in the database, it shows "NIP is used by the other".</p>
  
  <p>Can someone help me so my code can run like what I mentioned above?</p>
  
  <p>Thanks in advance</p>