我需要一个PHP代码来更新我的数据库表,只有我检查过的选项

时间:2015-06-04 08:11:06

标签: php html

我有一张学生桌,前面有复选框。但是,如果我点击我的促销按钮,我只想在数据库中检查更新的那些,其余的不应该。

这是我的HTML代码:

<table class="table toggle-square" data-filter="#table_search" width="792" border="0" align="center">
                          <tr>
                            <td width="92" height="26" bgcolor="#FBA774"><div align="center"><strong>S/N</strong></div></td>
                            <td width="131" bgcolor="#FBA774"><div align="center"><strong>Reg Number</strong></div></td>
                            <td width="152" bgcolor="#FBA774"><div align="center"><strong>Full name</strong></div></td>
                            <td width="140" bgcolor="#FBA774"><div align="center"><strong>Class</strong></div></td>
                            <td width="255" bgcolor="#FBA774"><div align="center"></div></td>


                          <? 
                               $i=0;
      while ($rowgeneral = mysql_fetch_array($sqldisplayresult)){
          $i++;
                            //$choice = $rowgeneral['stdcurrentclass'];
                            //if ($choice == "14"){
                            ?>
             <tr>
                            <td><div align="center">
                              <?=$i?>
                            </div></td>
                            <td><div align="center"><?=$rowgeneral['stdregnumber']?></div></td>
                            <td><div align="center">
                              <? 
                  $stdname = $rowgeneral['stdregnumber'];
                  $retrivestdnamequery = mysql_query("Select * from tb_student_reg where regnumber = '$stdname'");
                $stdnamerow = mysql_fetch_array($retrivestdnamequery);
                $mystdname = $stdnamerow['firstname'].' '.$stdnamerow['lastname'].' '.$stdnamerow['middlename'];
                              echo $mystdname;
                              ?>
                            </div></td>
                            <td><div align="center">
                             <? 
                  $classid = $rowgeneral['stdcurrentclass'];
                 $retriveclassnamequery = mysql_query("Select * from tb_classes where id = $classid");
                  $classnamerow = mysql_fetch_array($retriveclassnamequery);
                  $classname = $classnamerow['classname'];
                              echo $classname;
                              ?> 
                            </div></td>
                            <td><div align="center">
   <!--<input  type="checkbox" onChange="feetotal"  name="subject[]" value="<?=$rowgeneral['currentclass']?>" 
   checked onClick="return false">-->
     <? 
                            //echo $rowgeneral['avg_score'] . " >=  ".  $averagescore;
                            if ($rowgeneral['avg_score'] >= $averagescore){
                            ?>
            <input type="checkbox" name="checkbox" id="checkbox" checked>

                             <? }
                            else{
                            ?>
                             <input type="checkbox" name="checkbox" id="checkbox" >
                            <?
                            }?>
                            </div></td>
                     <? }?>

             <tr>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
             <tr>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td><div align="right">

                 <input type="submit" name="promote" id="promote" value="Promote">
               </div></td>
           </table>

以下是我更新的Php代码:

<?
   $updatepromotionquery = "";
if(isset($_POST['promote'])) {
    $promotedclass = $_POST['promotedclass'];
    $currentclass = $_POST['currentclass'];
    $checkbox = $_POST['checkbox'];


$updatepromotionquery = "UPDATE tb_student_reg SET
promotedclass ='$promotedclass'


WHERE currentclass = '$currentclass'";

mysql_query($updatepromotionquery);

}

?>

1 个答案:

答案 0 :(得分:0)

使用多重复选框

Intck()