我有一组包含五个字段的行。我的要求是,如果“Internal_Deadline”字段大于任何行中的“Client_Deadline”,则必须显示“内部截止日期不应大于客户截止日期”的警告。现在只检查第一行。我需要检查所有行。感谢
<?php
for( $i = 1; $i <= 100; $i++ )
{
$task = $_POST['task'.$i];
$Description = $_POST['Description'.$i];
$Internal_Deadline = $_POST['Internal_Deadline'.$i];
$Client_Deadline = $_POST['Client_Deadline'.$i];
$Actual_Deadline = $_POST['Actual_Deadline'.$i];
if(strtotime($Internal_Deadline) > strtotime($Client_Deadline)){
?>
<script>alert('Internal Deadline should not be greater than Client Deadline');</script>
<?php
}
else{
$result_task=mysql_query("select * from project_plan where p_id='$p_id' and task_no='$i'", $dbconnect1);
$row_task=mysql_fetch_array($result_task);
$id=$row_task['id'];
if(mysql_num_rows($result_task)!=0){
$update_result=mysql_query("update project_plan set Task='$task',Description='$Description',Internal_Deadline='$Internal_Deadline',Client_Deadline='$Client_Deadline',Actual_Deadline='$Actual_Deadline' where id='$id'", $dbconnect1);
}
else{
if($task!=""){
$que = mysql_query("insert INTO project_plan(task_no,Task,Description,Internal_Deadline,Client_Deadline,Actual_Deadline,Created_Date,p_id) VALUES ('".$i."','".$task."','".$Description."','".$Internal_Deadline."','".$Client_Deadline."','".$Actual_Deadline."','".$current_date."','".$p_id."')", $dbconnect1);
}
}
}
}
答案 0 :(得分:0)
首先,for循环的长度不正确。
您需要将此循环完全相同地运行到后期数据计数。
其次,我在本地尝试了您的给定数据(在您的评论中)。似乎不符合条件:
if(strtotime($Internal_Deadline) > strtotime($Client_Deadline)){
尝试这样:
它将跳过不必要的循环。如果您在发布数据中设置了task1,task2,task3,那么它将运行3次,而不是100次。
$i=1;
while(isset($_POST['task'.$i]))
{
$task = $_POST['task'.$i];
$Description = $_POST['Description'.$i];
$Internal_Deadline = $_POST['Internal_Deadline'.$i];
$Client_Deadline = $_POST['Client_Deadline'.$i];
$Actual_Deadline = $_POST['Actual_Deadline'.$i];
if(strtotime($Internal_Deadline) > strtotime($Client_Deadline)){
?>
<script>alert('Internal Deadline should not be greater than Client Deadline');</script>
<?php
}
else{
$result_task=mysql_query("select * from project_plan where p_id='$p_id' and task_no='$i'", $dbconnect1);
$row_task=mysql_fetch_array($result_task);
$id=$row_task['id'];
if(mysql_num_rows($result_task)!=0){
$update_result=mysql_query("update project_plan set Task='$task',Description='$Description',Internal_Deadline='$Internal_Deadline',Client_Deadline='$Client_Deadline',Actual_Deadline='$Actual_Deadline' where id='$id'", $dbconnect1);
}
else{
if($task!=""){
$que = mysql_query("insert INTO project_plan(task_no,Task,Description,Internal_Deadline,Client_Deadline,Actual_Deadline,Created_Date,p_id) VALUES ('".$i."','".$task."','".$Description."','".$Internal_Deadline."','".$Client_Deadline."','".$Actual_Deadline."','".$current_date."','".$p_id."')", $dbconnect1);
}
}
}
$i =$i +1;
}