简体   繁体   English

PHP通过FOREACH循环循环

[英]PHP Looping through a FOREACH loop

I have a FOREACH loop which is not picking up the first element in the array. 我有一个FOREACH循环,它没有拾取数组中的第一个元素。

I have a submit form which has the following: 我有一个提交表单,其中包含以下内容:

<input name="repaired[<?php echo $row_Faults['UniqueID']; ?>]" type="checkbox" id="repaired" value="1" class="required"/>

If I echo the $_POST['repair'] array I see two records but when the code is run the first record is not been processed. 如果我回显$ _POST ['repair']数组,则会看到两条记录,但是当代码运行时,第一条记录未得到处理。

foreach($_POST['repaired'] as $uniqueID => $repairedValue){   

$updateSQL = sprintf("UPDATE ".$Hist." SET Status=%s, LettoStatus=%s WHERE UniqueID= '".$_POST["UniqueID"]."'",
 GetSQLValueString($_POST['Status'] = $StatusCode , "int"),
GetSQLValueString($_POST['LettoStatus'] = $LettoCode , "int"));

mysql_select_db($database_iMaint, $iMaint);
$Result1 = mysql_query($updateSQL, $iMaint) or die(mysql_error());
}

Can anyone see where I am going wrong. 谁能看到我要去哪里错了。

Many thanks in advance for your time. 非常感谢您的宝贵时间。

You have $uniqueID variable initialized in your foreach but in your $updateSQL you still use $_POST["UniqueID"] So all you need is to change your $updateSQL 您已经在foreach中初始化了$uniqueID变量,但是在$ updateSQL中,您仍然使用$_POST["UniqueID"]因此您所需$updateSQL就是更改$updateSQL

$updateSQL = sprintf("UPDATE ".$Hist." SET Status=%s, LettoStatus=%s WHERE
    UniqueID= '".$uniqueID."'",    
    GetSQLValueString($_POST['Status'] = $StatusCode , "int"),
    GetSQLValueString($_POST['LettoStatus'] = $LettoCode , "int"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM