How to update multiple rows in database on one query with calculations
<p>How should I change the code in order to update multiple rows at once, when I click on submit?</p>

<h2>This is the code:</h2>

<pre><code>&lt;html&gt;
&lt;title&gt;&lt;/title&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form action="" method="post"&gt;
     &lt;table&gt;
      &lt;tr&gt;
       &lt;td&gt;&lt;h6&gt;Seatwork 1&lt;/h6&gt;&lt;/td&gt;
       &lt;td&gt;&lt;h6&gt;Seatwork 2&lt;/h6&gt;&lt;/td&gt;
       &lt;td&gt;&lt;h6&gt;Seatwork 3&lt;/h6&gt;&lt;/td&gt;
       &lt;td&gt;&lt;h6&gt;Quiz 1&lt;/h6&gt;&lt;/td&gt;
       &lt;td&gt;&lt;h6&gt;Quiz 2&lt;/h6&gt;&lt;/td&gt;
     &lt;/tr&gt;

     &lt;?php




        $query1="SELECT * FROM tbl...";
        $query = mysql_query($query1) or die(mysql_error());
          while($user = mysql_fetch_assoc($query)){

              $userid = $user['userid'];
              $first = $user['first_name'];
              $last = $user['last_name'];
              $subject = $user['subject'];                                
              $sw1 = $user['sw1'];
              $sw2 = $user['sw2'];
              $sw3 = $user['sw3'];
              $qz1 = $user['qz1'];
              $qz2= $user['qz2'];



            ?&gt;  
        &lt;tr&gt;
          &lt;td&gt;&lt;h6&gt;&lt;?php echo $first; ?&gt;&amp;nbsp;&lt;?php echo $last; ?&gt;&lt;/h6&gt;&lt;/td&gt;
            &lt;!-- Written Works --&gt;
          &lt;td&gt;&lt;input type="text" name="sw1" value="&lt;?php echo $ws1; ?&gt;"&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input type="text" name="sw2" value="&lt;?php echo $ws2; ?&gt;"&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input type="text" name="sw3" value="&lt;?php echo $ws3; ?&gt;"&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input type="text" name="qz1" value="&lt;?php echo $ws4; ?&gt;"&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input type="text" name="qz2" value="&lt;?php echo $ws5; ?&gt;"&gt;&lt;/td&gt;
       &lt;/tr&gt;

       &lt;?php } ?&gt;
     &lt;/table&gt;

       &lt;input type="submit" name="submit" value="submit"&gt;

&lt;/form&gt;
</code></pre>

<h1>Query for saving the rows:</h1>

<p>It saves but only if the value of the columns in a row are the same.
Please help me solve this problem. Thanks In advance.</p>

<pre><code>&lt;?php  

    if ($_POST["submit"]) {

       $sw1 = $_POST['sw1'];
       $sw2 = $_POST['sw2'];
       $sw3 = $_POST['sw3'];
       $qz1 = $_POST['qz1'];
       $qz2 = $_POST['qz2'];

       $WST = $sw1 + $sw2 + $sw3 + $qz1 + $qz2; 
       $WSP1 = ($WST / 150 )*100;
       $WSP =  number_format((float)$WSP1, 2, '.', '');


       $sql="UPDATE tbl_quarter1  set sw1 = '$sw1' , sw2 = '$sw2', 
             sw3 = '$sw3', qz1 = '$qz1', qz2 = '$qz2', 
             WST='$WST', WSP='$WSP'";
       mysql_query($sql) or die(mysql_error());
   }
?&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>