Hi all, I've been working on a php script that update school classes in a mysql database.

Below is the script i have worked on thus far and the images of how my database table is and how i want it to be after the update. Basically I want it to retain the "sub_class" when updating the "class" from the "dyn_class".



Code PHP:
 
if(isset($_POST['submit'])) {
 
 
$curYear = date('Y');
$end_year = $curYear+1;
$classA= 'JSS1';
$classB= 'JSS2';
$classC= 'JSS3';
$classD= 'SS1';
$classE= 'SS2';
$classF= 'SS3';
 
$check_all = mysql_query("select * from `student` where d_class='$classF' and year='$curYear'");
$get_all = mysql_fetch_array($check_all);
 
$subclass= $get_all['sub_class'];
 
$query1= mysql_query("update student set d_class='Senior-graduant', class='Senior-graduant', year='$end_year' where d_class='$classF' and year='$curYear'");
 
 
if($query1){
 
$check_all1 = mysql_query("select * from `student` order by `sub_class` desc");
$get_all1 = mysql_fetch_array($check_all1);
 
$subclass2= $get_all1['sub_class'];
 
 
$query2= mysql_query("update student set d_class='$classF', class='$classF$subclass2', year='$end_year' where d_class='$classE' and year='$curYear'");
 
 
if($query2){
 
$check_all2 = mysql_query("select * from `student` order by `sub_class` desc");
$get_all2 = mysql_fetch_array($check_all2);
 
$subclass3= $get_all2['sub_class'];
$query3= mysql_query("update student set d_class='$classE', class='$classE$subclass3' , year='$end_year' where d_class='$classD' and year='$curYear'");
 
 
 
if($query3){
 
$check_all3 = mysql_query("select * from `student` order by `sub_class` desc");
 ($get_all3 = mysql_fetch_array($check_all3);
 
$subclass4= $get_all3['sub_class'];
 
$query4= mysql_query("update student set d_class='Junior-graduant', class='Junior-Graduant' , year='$end_year' where d_class='$classC' and year='$curYear'");
}
 
if($query4){
$check_all4 = mysql_query("select * from `student` order by `sub_class` desc");
$get_all4 = mysql_fetch_array($check_all4);
 
$subclass5= $get_all4['sub_class'];
 
$query5= mysql_query("update student set d_class='$classC', class='$classC$subclass5' , year='$end_year' where d_class='$classB' and year='$curYear'");
}
 
 
if($query5){
$check_all5 = mysql_query("select * from `student` order by `sub_class` desc");
$get_all5 = mysql_fetch_array($check_all5);
 
$subclass6= $get_all5['sub_class'];
 
$query6= mysql_query("update student set d_class='$classB', class='$classB$subclass6' , year='$end_year' where d_class='$classA' and year='$curYear'");
 
 
if($query6){ echo"Classes updated successfully!";} else{echo 'Could not update classes!';}
 
}
 
 
}
 
}
 
}
 
}
 
}
}
 
?>

This is how it looks like before the update.

normal.jpg



This is how I want it to look like after the update.

UPDATED.jpg

Thanks as i await your responses.