更新表中与多行的另一个表对应的多行

时间:2016-11-29 06:27:19

标签: php mysql arrays

我真的不知道怎么开始这个,所以我试着在这里写。
我有两张桌子: SUBJECT TAKEN-SUBJECT



SUBJECT  
<table>
  <tr>
    <th>SCODE</th>
    <th>DAY</th>
    <th>TIME</th>
    <th>SLOT</th>
  </tr>
  <tr>
    <td>MATH</td>
    <td>TTH</td>
    <td>7:30-9:00</td>
    <td>19</td>
  </tr>
  <tr>
    <td>ENGLISH</td>
    <td>TTH</td>
    <td>9:30-11:00</td>
    <td>19</td>
  </tr>
     <tr>
    <td>PE 1</td>
    <td>MWF</td>
    <td>3:00-4:00</td>
    <td>19</td>
  </tr>
     <tr>
    <td>MATH</td>
    <td>MWF</td>
    <td>9:30-10:30</td>
    <td>20</td>
  </tr>
</table> 


</br>
</br>


TAKEN SUBJECT 
<table>
  <tr>
    <th>SCODE</th>
    <th>DAY</th>
    <th>TIME</th>
   
  </tr>
  <tr>
    <td>MATH</td>
    <td>TTH</td>
    <td>7:30-9:00</td>
   
  </tr>
  <tr>
    <td>ENGLISH</td>
    <td>TTH</td>
    <td>9:30-11:00</td>
   
  </tr>
     <tr>
    <td>PE 1</td>
    <td>MWF</td>
    <td>3:30-4:00</td>
    
  </tr>

</table> 
&#13;
&#13;
&#13;

所有受试者都有20个插槽,因此每个受试者都将其扣除为1并且如果所有拍摄对象都将被删除,则将该插槽返回到主体,因此它再次变为20,所有3个主体都有19个。 />

// QUERY TAKEN SUBJECT

$check=mysqli_query($link,"SELECT * FROM takensubject where S_ID = '$S_ID' and SchoolYear ='$Sy' and Semester ='$Sem'ORDER BY SubjectCode ASC ");
    $checkrows=mysqli_num_rows($check);
    if($checkrows>0) {  
    while($row = mysqli_fetch_assoc($check)) {
      $scode = $row['SubjectCode'];
      $day = $row['Day'];
      $time= $row['Time'];
      $Slot = $row['Slot'];
    }
  }

//结束

// UPDATE QUERY

$check="UPDATE schedule set Slot = Slot + 1 where SubjectCode='$scode' and Day='$day' and Time='$time'";
    if (mysqli_query($link, $check)) {
        echo "Update Success ";
    } else {
        echo "Error updating record: " . mysqli_error($link);
    }

// END

但它只更新了1个主题
如何使用它?

0 个答案:

没有答案