Periode
Mean
SD
Range -

"; if(isset($data[$i])) { echo ""; } else { echo ""; } if(isset($comment[$i])) { echo ""; } else { echo ""; } } ?>
Day Result Comment
$i
Comment:
0) {$rdata[$i]=$data1;} $i++; } $data = $rdata; $hari = date("t",strtotime("$date-1")); $sql = "SELECT id,resdate FROM DAILY_RESULT WHERE convert(varchar(7),resdate,126) ='$date' and controlid='$control' and testid='$testid'"; //echo $sql; $stmt = sqlsrv_query( $conn1, $sql); while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC ) ) { $id = $row[0]; $cday = date_format($row[1],"j"); $resid[$cday] = $id; } ///* for($i=1;$i<=$hari;$i++) { if( isset($data[$i]) ) { if( isset($resid[$i]) ) { $dataUpdate[$resid[$i]] = $data[$i]; $commentUpdate[$resid[$i]]= $comment[$i]; } // data update else { $dataInsert[$i] = $data[$i]; } // data insert } elseif( isset($resid[$i]) ) { $dataDelete[] = $resid[$i]; } // data delete } //INSERT if(isset($dataInsert)) { $sql = "INSERT INTO DAILY_RESULT (controlid, testid, resdate, resvalue, rescomment ) VALUES "; foreach($dataInsert as $day => $data1) { if($day < 10) { $day="0$day"; } $sql.= "('$control', '$testid', '$date-$day', '$data1','$comment[$day]'),"; } $sql = substr($sql,0,-1); $stmt = sqlsrv_query( $conn1, $sql); if( $stmt === false ) { die( print_r( sqlsrv_errors(), true)); } echo "inserting new control result done...
"; } //UPDATE if(isset($dataUpdate)) { foreach($dataUpdate as $drid => $data1) { $sql = "update DAILY_RESULT set resvalue='$data1', rescomment='$commentUpdate[$drid]' where id='$drid'"; $stmt = sqlsrv_query( $conn1, $sql); if( $stmt === false ) { die( print_r( sqlsrv_errors(), true)); } //echo "update $drid
"; } echo "updating control result done...
"; } //DELETE if(isset($dataDelete)) { foreach($dataDelete as $drid ) { $sql = "delete from DAILY_RESULT where id='$drid'"; $stmt = sqlsrv_query( $conn1, $sql); if( $stmt === false ) { die( print_r( sqlsrv_errors(), true)); } //echo "delete $drid $sql
"; } echo "deleting control result done...
"; } $comtext = $_POST['monthlycomment']; if( $comtext != '' ) { $sql = "if exists (select * from MONTHLY_COMMENT with (updlock,serializable) where commonth='$date' and controlid='$control' and testid='$testid') begin update MONTHLY_COMMENT set comtext='$comtext' where commonth='$date' and controlid='$control' and testid='$testid' end else begin insert into MONTHLY_COMMENT (controlid, testid, commonth, comtext ) values ('$control', '$testid', '$date', '$comtext') end"; echo $sql; $stmt = sqlsrv_query( $conn1, $sql); if( $stmt === false ) { die( print_r( sqlsrv_errors(), true)); } echo "updating comment done
"; } else { $sql = "delete from MONTHLY_COMMENT where commonth='$date' and controlid='$control' and testid='$testid'"; $stmt = sqlsrv_query( $conn1, $sql); if( $stmt === false ) { die( print_r( sqlsrv_errors(), true)); } echo "deleting comment done
"; } //echo "
redirecting ...."; echo "
redirecting ...."; //*/ } ?>