title: Swapping Rows in Database tables By using the primary Key In php/mysql
body: <p>In my application i want to swap rows in database.</p>
  
  <p>That means , my table has following strusure,</p>
  
  <pre><code>Column     Type             Null    Default     Comments
  
  intid         int(11)           No           
  intuserid         int(11)           No           
  vchimagename      varchar(50)   No  
  </code></pre>
  
  <p>Here intid is primary key.</p>
  
  <p>When i using this function for wsapping ,</p>
  
  <pre><code>function row_swap($table, $id1, $id2)
  {
      if (!mysql_query("UPDATE $table SET intid='$id1' where intid='$id2'"))
      {
          echo mysql_error() ;
          exit ;
      }
      if (!mysql_query("UPDATE $table SET intid='$id2' where intid='$id1'"))
      {
          echo mysql_error() ;
          exit ;
      }
  
      return 1;
  } 
  </code></pre>
  
  <p>Calling function ,</p>
  
  <pre><code>row_swap('tblupload', 7, 8) ;
  </code></pre>
  
  <p>Then it displays error,</p>
  
  <pre><code>Duplicate entry '8' for key 'PRIMARY'
  </code></pre>
  
  <p>So how can i swap rows by using thier primary key?</p>
  
  <p>If it is possible?</p>